<!doctype html> <html> <head> <meta charset="UTF-8" /> <title>json实战</title> </head> <body> <ul id="myDiv"> <li>111</li> </ul> <button id="btn">加载</button> </body> <script type="text/javascript"> window.onload = function(){ var Btn = document.getElementById("btn"); Btn.addEventListener('click',function(){ chuFa(); }) } function chuFa() { var myXMLHttpRequest = null; if (window.ActiveXObject) { myXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } else { myXMLHttpRequest = new XMLHttpRequest(); } var url = "http://192.168.1.35:8860/helloJson.json"; var data = "key=val"; myXMLHttpRequest.open("get", url, true); myXMLHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); myXMLHttpRequest.onreadystatechange = function(){ if (myXMLHttpRequest.readyState == 4 && myXMLHttpRequest.status == 200) { var res = myXMLHttpRequest.responseText; var jsonObj = eval("("+res+")"); for(var i=0; i < jsonObj.length; i++){ var info = "<li>"+ jsonObj.name +"</li>"; document.getElementById("myDiv").appendChild(info); } } } myXMLHttpRequest.send(data); } </script> </html>
Joy_Sang
梦里_QAQ3545330
慕粉3581752
损失函数
相关分类