<!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <html> <head> <title>异步调用json</title> </head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script type="text/javascript"> <!-- var xmlhttp; // 创建xmlhttprequest对象 function createxmlhttprequest() { if(window.activexobject)//②如果当前浏览器为ie { xmlhttp = new activexobject("microsoft.xmlhttp"); } else if(window.xmlhttprequest)//③如果是其他浏览器 { xmlhttp = new xmlhttprequest(); }else { alert("your browser does not support xmlhttp."); } } function getinfo() { createxmlhttprequest(); xmlhttp.open("get", "http://audicms.ogilvy.com.cn/webapp/front/dealerapi!getdealerlist.action", true); xmlhttp.onreadystatechange = returninfo; xmlhttp.send(null); } function returninfo() { if(xmlhttp.readystate == 4) { var info = xmlhttp.responsetext; eval("var json= " + info); var message=""; var dealerlocation=""; var salesphone=""; for(var i=0;i<json.dealers.length;i++){ message+="经销商名称:<font style='color:red;'>" + json.dealers[i].name + "</font> <br/>"; salesphone+="经销商电话:<font style='color:red;'>" + json.dealers[i].salesphone + "</font> <br/>"; dealerlocation+="经销商经纬度:<font style='color:red;'>" + json.dealers[i].location + "</font> <br/>"; } document.getelementbyid("showinfo").innerhtml = message; document.getelementbyid("salesphone").innerhtml = salesphone document.getelementbyid("location").innerhtml=dealerlocation; } } --> </script> <body> <br/><br/> <h2 style="color: red;">异步调用json</h2> <br/><input type="button" value="获取json数据" onclick="getinfo()" /> <table> <tr> <td><div id="showinfo"></div></td> <td><span id="salesphone"><span></td> <td><span id="location"><span></td> </tr> </table> </body> </html>
上面是我整理给大家的有关在js 获取json数据简单调用,希望今后会对大家有帮助。
相关文章:
入门级video.js使用笔记(代码附上)
畅谈在原生js与其他js 区别
在 js中function前面加!方面的问题,代码附上
以上就是有关在js 获取json数据简单调用(代码附上,简单粗暴)的详细内容。
