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