简单的ajax封装:
function ajax(url,onsuccess,onfail)
{
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open("POST", url, true);
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
onsuccess(xmlhttp.responseText);
}
else
{
onfail(xmlhttp.status);
}
}
}
xmlhttp.send(); //这时才开始发送请求
}
简单的Ajax封装
最新推荐文章于 2021-08-05 15:27:41 发布