//定義全局變量
var xmlhttp;
//封裝的函數
function getxmlhttp(){
// 判斷是否是ie浏覽器 i
f(window.activexobject){
xmlhttp = new
activexobject("microsoft.xmlhttp");
}else
if(window.xmlhttprequest){
xmlhttp = new xmlhttprequest();
}
//調用的方法 function sendparam(url){
// 調用封裝的函數
getxmlhttp();
// get:調用的方法 check.php?user="+url:要調用的php true:使用ajax送出
xmlhttp.open("get","sign_mysql.php?user="+url,true);
// post的調用方法
//
setrequestheader("content-type","application/x-www-form-urlencoded");
// onreadystatechange:改變狀态的事件觸發器
// 調用封裝好的函數
xmlhttp.onreadystatechange = gettxt;
// send:發送請求
// 發送請求到check.php頁面
xmlhttp.send(null);
//顯示的方法
function gettxt(){
// readystate:對象狀态(integer):0=未初始化,1=讀取中,2=已讀取,3=互動中,4=完成
if(xmlhttp.readystate == 4){
//
status:伺服器傳回的狀态碼,如404=“檔案未找到”、200=“成功”
if(xmlhttp.status == 200){
var sp = document.getelementbyid("tishi");
//
将網頁與php進行連接配接,顯示出來
sp.innerhtml = xmlhttp.responsetext;
}
總結:清楚的知道上面的每一步在幹嘛,然後自己照着寫一次,做些練習,那就掌握今天學的知識了;