您的位置:首页 > 其它

简单的Ajax封装

2014-04-07 16:42 225 查看
简单的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