ajax基本通用代码示例
发布时间:2020-12-15 23:06:59 所属栏目:百科 来源:网络整理
导读:本篇章节讲解ajax基本通用代码。供大家参考研究具体如下: htmlheadscript type="text/JavaScript"var xmlhttpfunction loadXMLDoc(url){ // code for Mozilla,etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() xmlhttp.onreadyst
本篇章节讲解ajax基本通用代码。分享给大家供大家参考,具体如下: <html> <head> <script type="text/JavaScript"> var xmlhttp function loadXMLDoc(url) { // code for Mozilla,etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET",url,true) xmlhttp.send(null) } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") if (xmlhttp) { xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET",true) xmlhttp.send() } } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { document.getElementById('T1').innerHTML=xmlhttp.responseText } else { alert("Problem retrieving data:" + xmlhttp.statusText) } } } </script> </head> <body onload="loadXMLDoc('test_xmlhttp.txt')"> <div id="T1" style="border:1px solid black;height:40;width:300"></div><br /> <button onclick="loadXMLDoc('test_xmlhttp2.txt')">Click</button> </body> </html> 更多关于ajax相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《JavaScript中ajax操作技巧总结》、《PHP+ajax技巧与应用小结》及《asp.net ajax技巧总结专题》。 希望本文所述对大家ajax程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |