原生ajax调用服务器上的json数据

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>json</title>
</head>
    <button>点击</button>
<body>
    <script type="text/javascript">
    document.getElementsByTagName('button')[0].onclick=function(){
                    var xml = null;
         if(window.XMLHttpRequest) {
            xml = new XMLHttpRequest();
         }else{
            xml = new ActiveXObject("Microsoft.XMLHTTP");
         }; 
         xml.open('get','testJson.json',true);
         xml.send();
         xml.onreadystatechange=function(){
              if(xml.readyState==4){
                 alert(xml.status);
                 if(xml.status==200){
                     var ojson = JSON.parse(xml.responseText);
                    console.log(ojson.Result[0].Id);
                 }else{
                    alert("muyou")
                 }
              }
         } 
    }
         
       
        
    </script>
</body>
</html>
json
{
    "Method": "BIZLIST",
    "Code": 1,
    "Message": "",
    "Result":[
        {
            "Id": 362392,
            "UserId": 118728,
            "CompanyName": "xxxxxxxxxxxxxxxx",
            "BizTitle": "xxxxxxxx",
            "BizType": "212012005,",
            "Productpic": "/Ashx/IWebSee.ashx?metod=ImgSeam&p=http://img.spzs.com/UPLDFILES/s_635429540015.jpg",
            "SendTime": "2016-08-06 16:46:29",
            "Time": "0001-01-01 00:00:00",
            "IsBid": 0,
            "Px": 0,
            "Verify": 1,
            "VipIconTip": "1",
            "NoPassTip": null
        }
      ]
       }

 

posted @ 2017-02-19 10:49  xuanPhoto  阅读(122)  评论(0)    收藏  举报