url为具体的url地址,
onsuccess为正常返回时的结果,
onfail为错误返回时的结果
function MyAjax(url,onsuccess,onfail) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xhr.open("POST", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
onsuccess(xhr.responseText);
}
else {
onfail(xhr.status);
}
}
};
xhr.send();
}