【问题标题】:jQuery .find() not working in Internet Explorer 7 and Internet Explorer 8jQuery .find() 在 Internet Explorer 7 和 Internet Explorer 8 中不起作用
【发布时间】:2012-06-07 06:48:23
【问题描述】:

我正在我的程序中使用 jQuery 的 .ajax() 检索 HTML 数据。

在 Internet Explorer 9、Chrome、Firefox 和 Opera 中一切顺利。

Internet Explorer 7Internet Explorer 8 存在问题。

我的jQuery代码如下。

$j.ajax({
    type:'POST',
    datatype:'HTML',
    url:processUrl,
    success:function(data){
        alert(data);
        var testdata = $j(data).find(".category-products");
        alert(testdata.html());
        $j(".col-main .category-products").empty().replaceWith(testdata);
    },
    complete: function(){
        //Doing something
    }
});

现在,当我提醒 data 时,我会获取我的 HTML 数据(在 Internet Explorer 7 和 Internet Explorer 8 中也是如此)。

但是,当我提醒 testdata 时,我会在 Internet Explorer 7 和 Internet Explorer 8 中收到 null

我该如何解决这个问题?

您可以查看错误here(按数字进行分页)-

如果您正在调试,那么您会在第 11949 行找到我的代码。脚本文件的名称会很长,因为它会在运行时合并其他脚本文件。

更新

我在 localhost 上实现了相同的解决方案,它在所有浏览器上都运行良好。是服务器问题吗?

更新 2

问题已解决,我猜这是服务器上的缓存问题,因为我在不同的位置安装了我的项目的新副本,并且它在所有浏览器中都可以正常工作。

【问题讨论】:

标签: jquery ajax internet-explorer-8 internet-explorer-7


【解决方案1】:
success:function(data){
       alert(data);
       var temp = $j('<div/>').append(data); // Here is the trick:
                                             // Set the data to a
                                             // temporary element.
       var testdata = $j(temp ).find(".category-products"); // Then find
       alert(testdata.html());
       ...
 },

如果上述方法不起作用,请使用hidden div。假设:

<div id="imhidden"></div>

然后执行以下操作:

success:function(data){
        alert(data);
        $j('#imhidden').html(data); // Here is the trick:
                                    // Set the data to that
                                    // hidden div.

        var testdata = $j('#imhidden').find(".category-products"); // Then find
        alert(testdata.html());
        ...
},

【讨论】:

  • @Tarun 不,任何浏览器都没有问题
  • 好的,现在就试试你的解决方案。
  • 不工作,当我发出警报时仍会收到null。在其他浏览器中工作正常
  • 我添加了我的作品的链接,请看一下。希望对你有帮助
  • 问题已经解决,我猜是服务器缓存问题,因为我在不同的位置安装了我的项目的新副本,它在所有浏览器中都可以正常工作跨度>
猜你喜欢
  • 2023-04-09
  • 2017-08-06
  • 2011-09-08
  • 2010-10-09
  • 2011-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多