首页 > 代码库 > 使用XMLHttpRequest解析json
使用XMLHttpRequest解析json
不适用内函数或者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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。