2012-06-02 259 views
1

不工作,我在我的程序检索HTML数据与jQuery的.ajax()jQuery的.find()在Internet Explorer 7和Internet Explorer 8

所有的快乐在互联网 资源管理器  9,铬,火狐和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中和Internet Explorer的为好)。

但是,当我提醒testdata,我在互联网浏览器和Internet Explorer的

我如何去解决这个问题得到null

你可以看看错误here(打号码分页) -

如果你正在调试,那么你会在行11949.找到我的代码的脚本文件将有很长的怪异因为它在运行时合并其他脚本文件。

UPDATE

我实现了在本地主机上相同的解决方案,并且它在所有浏览器工作正常。这是服务器问题吗?

更新2

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

+3

HVE你试图警报($(TESTDATA)的.html()); ? – Robbie

+0

检查该响应,它的工作对我来说:http://stackoverflow.com/a/12057929/15329 –

回答

2
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 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()); 
     ... 
}, 
+0

这不会破坏工作在其他浏览器,对不对? –

+0

@Tarun没有,任何浏览器没有问题 – thecodeparadox

+0

好了,刚才想您的解决方案。 –