js调用ajax案例

时间:2018-11-14 00:25:38   收藏:0   阅读:165

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>

原文:https://www.cnblogs.com/1175429393wljblog/p/9955706.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!