2012-06-02 216 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

好了,剛纔想您的解決方案。 –