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>

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