JS JSON 데이터 단순 호출 가 져 오기

2832 단어 json
<!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();
         }
    }
    
    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>



좋은 웹페이지 즐겨찾기