ajax原理和XmlHttpRequest对象

function CreateXmlHttp() {

//非IE浏览器创建XmlHttpRequest对象

if (window.XmlHttpRequest) {

xmlhttp = new XmlHttpRequest();

}

//IE浏览器创建XmlHttpRequest对象

if (window.ActiveXObject) {

try {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (e) {

try {

xmlhttp = new ActiveXObject("msxml2.XMLHTTP");

}

catch (ex) { }

}

}

}

function Ustbwuyi() {

var data = document.getElementById("username").value;

CreateXmlHttp();

if (!xmlhttp) {

alert("创建xmlhttp对象异常!");

return false;

}

xmlhttp.open("POST", url, false);

xmlhttp.onreadystatechange = function () {

if (xmlhttp.readyState == 4) {

document.getElementById("user1").innerHTML = "数据正在加载...";

if (xmlhttp.status == 200) {

document.write(xmlhttp.responseText);

}

}

}

xmlhttp.send();

}

有些事现在不做,一辈子都不会做了
原文地址:https://www.cnblogs.com/mengkai/p/6187680.html