js调用ajax案例


js调用ajax案例

测试地址:http://www.w3school.com.cn/tiy/t.asp?f=ajax_get

嵌入下面代码,点击提交,再点击请求数据。就可以看到结果了。

<html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest)   {// code for IE7+, Firefox, Chrome, Opera, Safari   xmlhttp=new XMLHttpRequest();   } else   {// code for IE6, IE5   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   } xmlhttp.onreadystatechange=function()   {   if (xmlhttp.readyState==4 && xmlhttp.status==200)     {     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;     }   } xmlhttp.open("GET","http://127.0.0.1:27100/Terminal?t=FaceValidateWithIdCard&serviceId=32101412123&timeout=60&s="+Math.random()*10,false); xmlhttp.send(); } </script> </head> <body>

<h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">请求数据</button> <div id="myDiv"></div>

</body> </html>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM