function ajax( aJson )
{
var xhr = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
var method = aJson.method || 'get',
url = aJson.url,
aysn = aJson.aysn || true,
data = aJson.data || '',
success = aJson.success,
error = aJson.error;
if ( method.toLowerCase() == 'get' )
url += '?'+data+'&'+new Date().getTime();
xhr.open( method, url , aysn);
xhr.setRequestHeader('content-type' , 'application/x-www-form-urlencoded');
xhr.send(data);
xhr.onreadystatechange = function(){
if ( xhr.readyState == 4 )
{
if ( xhr.status >= 200 && xhr.status<300 )
{
success && success(xhr.responseText);
}
else
{
error && error();
}
}
}
}
js原声ajax包(兼容个浏览器)
最新推荐文章于 2022-08-21 17:41:25 发布