2012-12-14 30 views
1

使用JavaScript我需要一個XML配置加載到一個DIV,對於我使用下面的代碼:問題加載XML到DIV在IE

$(document).ready(function(){ 
        console.log("Document ready"); 
     $("#footer_config").load("/config/footer_config.xml"); 
    }); 

此代碼確定在Chrome,但它不」 t在IE中。它在控制檯中打印「Document ready」,但「footer_config」DIV爲空。如果我在IE中按下CTRL + F5,它將起作用,並且div具有XML文件的內容。我正在使用IE 9.

任何想法?

在此先感謝!

+0

你嘗試沒有的console.log? – adeneo

+0

是的,起初它沒有console.log,我把它放在那裏檢查$(document).ready是否被執行。 – mxch

回答

1

試試這個:

$(function(){ 
    console.log("Document ready"); 
    $("#footer_config").load('/config/footer_config.xml', function() { 
     console.log('Load finished'); 
    }); 
}); 

這會告訴你,在加載完成。之後嘗試查看Chrome開發者工具中的網絡標籤,查看它是否被拉下。

更新:

而不是使用負載的方法,嘗試用AJAX方法拉下來:

$.ajax({url: '/config/footer_config.xml', dataType: 'xml', cache: false, success: function(d) { 
    console.log(d); 
    $('#footer_config').html($(d).html(); 
}}); 
+0

究竟是如何檢查Internet Explorer中的Chrome開發人員工具,因爲這是唯一的瀏覽器失敗? – adeneo

+0

您可以檢查服務器日誌以查看是否訪問了URL。 – Barmar

+0

我試着用console.log('加載完成')。它打印「加載完成」,但它不會將XML加載到DIV中。這隻會在頁面被緩存時產生。如果我清理緩存,則DIV使用XML加載 – mxch