为啥ie下可以,火狐不行呢

来源:1-2 使用getJSON()方法异步加载JSON格式数据

m条腿

2017-06-08 15:12

为啥ie下可以,火狐不行呢,火狐显示未定义。。。

$(function () {
   $("#btnShow").on("click", function () {
       var $this = $(this);
       $.getJSON("data/sport.json", function (data) {
           $this.attr("disabled", "true");
           $.each(data, function (index,sport) {
              $("ul").append('<li>'+sport["name"]+"</li>");
           });
       })
   });
})


[{"name":"3"},{"name":"5"},{"name":"5"}]

http://img.mukewang.com/5938fc770001ace403160224.jpg

http://img.mukewang.com/5938fc770001db8903620258.jpg


写回答 关注

1回答

  • m条腿
    2017-06-08 16:19:01

    搜了一段浏览器兼容代码,加上就可以了,

    function gethttp(sid, url) {  

        var xmlHttp;  

        if (window.ActiveXObject) {  

            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  

        }  

        else if (window.XMLHttpRequest) {  

            xmlHttp = new XMLHttpRequest();  

        }  

      

        xmlHttp.onreadystatechange = function() {  

            if (xmlHttp.readyState == 4) {  

                document.getElementById(sid).innerHTML = xmlHttp.responseText;  

            }  

        }  

      

        xmlHttp.open("POST", url, true);  

        xmlHttp.send(null);  



jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69095 学习 · 400 问题

查看课程

相似问题