码迷,mamicode.com
首页 > Web开发 > 详细

使用XMLHttpRequest解析json

时间:2017-04-17 15:48:37      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:gps   title   char   blog   input   return   ==   解析   rom   

不适用内函数或者promise的方式,可以在外部提取到json数据

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
        function createXHR(){
            var xhr = null;
            if(window.XMLHttpRequest){
                xhr = new XMLHttpRequest();
            }else if(window.ActiveXObject){
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            return xhr;
        }

        function test1(){
            var xhr = createXHR();
            xhr.open(GET,http://localhost/firstphp/js/SiteGPS.js,true);
            xhr.onreadystatechange = function(){
                if(this.readyState == 4){
                   alert(this.responseText);
                }
            }
            xhr.send(null);
        }
    </script>
</head>
<body>
    <input type="button" value="更新歌曲" onclick="test1();">
    <div id="lists"></div>
</body>
</html>

 

使用XMLHttpRequest解析json

标签:gps   title   char   blog   input   return   ==   解析   rom   

原文地址:http://www.cnblogs.com/vactor/p/6723153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!