JS中怎样用ajax通过url来传给服务器?

是两个值
2025-02-25 22:13:45
推荐回答(1个)
回答1:

var XMLHttp;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
XMLHttp=new XMLHttpRequest();
}
else if(window.ActiveObject)
{
XMLHttp=new ActiveObject("Microsoft.XMLHttp");
}
}

function doAjax()
{
createXMLHttpRequest();
if(XMLHttp!=null)
{
XMLHttp.open("post", "login", true);
XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
XMLHttp.onreadystatechange=proc;
XMLHttp.send(null);
}
else
{
alert("不能创建xml对象");
}

}

function proc()
{
if(XMLHttp.readyState==4)
{
if(XMLHttp.status==200)
{
var sob=document.getElementById("login");
var str=XMLHttp.responseText;
if(str!=0)
{
parent.frames["b_frame"].document.getElementById("login").innerHTML = "success!!!";
}
else
{
parent.frames["b_frame"].document.getElementById("login").innerHTML = "error!!!";
}
}
}
}

领悟吧 哥们