首先介紹get()函數:
url,[data],[callback],[type]
參數說明:
url:待載入頁面的URL地址
data:待發送 Key/value 參數。
callback:載入成功時回調函數。
type:返回內容格式,xml, html, script, json, text, _default。
首先建立testGet.php實例:
<?php$web = $_GET['webname'];echo "你現在訪問的網站是:".$web;?>
然見建立ajax.html文件:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>php點點通 - 關注php開發,提供專業web開發教程! </title><script type="text/javascript" src="./jquery-1.7.1.min.js"></script><script> $(document).ready(function(){ $("#btn").click(function(){ $.get("testGet.php",{web:"www.phpddt.com"},function(data,textStatus){ $("#result").append("data:"+data); $("#result").append("<br>textStatus:"+textStatus); }); }); });</script></head><body><input type="button" value="測試" id="btn" /><h2>顯示的內容如下:</h2><div id="result"></div></body></html>
測試前的初始頁面是:
點擊測試后的結果是: