写一个函数用来创建XMLHttpRequest对象。 function createXMLHttpRequest(){ if(window.ActiveXObject){ //这个是创建一个IE浏览器的 XMLHttpRequest对象; xmlHttp = new ActiveXObject(‘Microsoft.XMLHTTP’); } else{ //这个是创建一个其他浏览器的XMLHttpRequest对象; xmlHttp = new XMLHttpRequest(); } } 3.定义一个回调函数,用于处理你想处理的数据。 function handleStateChange(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ //在这里写你要实现的功能 alert(“OK”); } } }
定义一个函数,用于与服务器端进行通信。 function doSearch(){ //创建XMLHttpRequest对象; createXMLHttpRequest(); //将回调函数赋值给XMLHttpRequest对象的onreadystatechange方法; xmlHttp.onreadystatechange = handleStateChange; //调用XMLHttpRequest对象的open方法,并且给定相关参数 xmlHttp.open(“GET”,”dynamicContent.xml”,true); xmlHttp.send(null); }
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!