标签:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
</style>
<script>
function ajax(url, fnSucc, fnFaild)
{
//1.创建ajax
if(window.XMLHttpRequest)
{
var oAjax=new XMLHttpRequest();
}
else
{
var oAjax=new ActiveXObject(‘Microsoft.XMLHttp‘);
}
//2.连接-open
oAjax.open(‘GET‘, url, true);
/*****************************
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(parameter);
*****************************/
//3.发送-send
oAjax.send();
//4.接收-onreadystatechange
oAjax.onreadystatechange=function ()
{
if(oAjax.readyState==4)
{
//成功?
if(oAjax.status>=200 && oAjax.status<300 || oAjax.status==304)
{
//alert(‘成功:‘+oAjax.responseText);
fnSucc && fnSucc(oAjax.responseText);
}
else
{
//alert(‘失败‘);
fnFaild && fnFaild();
}
}
};
}
window.onload=function ()
{
var oBtn=document.getElementById(‘btn1‘);
oBtn.onclick=function ()
{
ajax(‘a.txt?t=‘+Math.random(), function (str){
alert(str);
}, function (){
alert(‘失败‘);
});
};
};
</script>
</head>
<body>
<input type="button" value="aaa" id="btn1" />
</body>
</html>
ajax
标签:
原文地址:http://www.cnblogs.com/xiaoleidiv/p/4607192.html