jQuery中Ajax的load方法详解
先来看一个Ajax例子
<!DOCTYPEhtml>
<html>
<headlang="en">
<metacharset="UTF-8">
<title></title>
</head>
<body>
<inputtype="button"value="Ajax提交"onclick="Ajax();"/>
<divid="resText"></div>
</body>
<scripttype="text/javascript">
functionAjax(){
varxmlHttpReq=null;//声明一个空对象用来装入XMLHttpRequest对象
if(window.ActiveXObject){
xmlHttpReq=newActiveXObject("Microsoft.XMLHTTP");//IE5IE6是以ActiveXObject的方式引入XMLHttpRequest的
}elseif(window.XMLHttpRequest){//除IE5IE6以外的浏览器XMLHttpRequest是window的子对象
xmlHttpReq=newXMLHttpRequest();//实例化一个XMLHttpRequest对象
}
if(xmlHttpReq!=null){
xmlHttpReq.open("GET","test.jsp",true);//调用open()方法并采用异步方式
xmlHttpReq.onreadystatechange=RequestCallBack;//设置回调函数
xmlHttpReq.send(null);//因为使用get方式提交,所以可以使用null参调用
}
functionRequestCallBack(){//一旦readyState值改变,将会调用这个函数} if(xmlHttpReq.readyState==4){ if(xmlHttpReq.status==200){ //将xmlHttpReq.responseText的值赋予id为resText的元素 document.getElementById("resText").innerHTML=xmlHttpReq.responseText; } } } }
</script> </html>