(1)写发送代码
var myXmlHttpRequest = "";
myXmlHttpRequest = getXmlHttpRequest();
if (myXmlHttpRequest) { //xmlHttpRequest创建成功了,才能发送请求
//地址一定要写正确
var url = "../zhuCe/zhuCeYanZheng.aspx?username=" + $('Text1').value;
myXmlHttpRequest.open("get",url,true);
myXmlHttpRequest.onreadystatechange = getData;
myXmlHttpRequest.send(null);
}
(2)写接受数据代码: function getData() { if((myXmlHttpRequest.readyState == 4) && (myXmlHttpRequest.status == 200)){ //alert("nihao"); var returnMessage = myXmlHttpRequest.responseText; //alert(returnMessage); if (returnMessage == "用户名不正确"){ alert("aaa"); } } } (3)另外需要加两个函数 function getXmlHttpRequest() { var xmlHttpRequest; if(window.ActiveXObject){ xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }else{ xmlHttpRequest = new xmlHttpRequest(); } return xmlHttpRequest; } function $(id) { return document.getElementById (id); }