First page Back Continue Last page Overview Graphics
建立一個簡單的AJAX系統
function login()
{
url= "auth_ajax.php?id="+document.getElementById("name").value+"&pwd="+
document.getElementById("pwd").value;
try
{ xhr=new XMLHttpRequest(); //建立一個AJAX物件
if (xhr.overrideMimeType) xhr.overrideMimeType('text/xml');}
catch (e) { try
{ xhr=new ActiveXObject("Msxml2.XMLHTTP"); }//如果標準的建不起來,用IE的方法建立
catch (ee)
{ alert("Your Browser doesn't support XMLHttpRequest"); return false; }}
xhr.onreadystatechange = function()
{
if (xhr.readyState==4 && xhr.status==200) //如果呼叫成功,處理底下
{ alert(xhr.responseText);}
}
xhr.open("get",url,true);
xhr.setRequestHeader('Content-Type','application/x-www-urlencoded; charset=utf-8');
xhr.send(null);
}