简体   繁体   English

在IE中使用JavaScript将XML加载到DIV中的问题

[英]Issue loading XML into DIV using JavaScript in IE

I need to load a configuration XML into a DIV, for that I'm using the following code: 我需要将配置XML加载到DIV中,为此,我正在使用以下代码:

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

This code works ok in Chrome but it doesn't in IE. 这段代码在Chrome中可以正常运行,但在IE中则不能。 It prints "Document ready" in the console but the "footer_config" DIV is empty. 它在控制台中打印“ Document ready”,但“ footer_config” DIV为空。 If I press CTRL+F5 in IE it works and the div has the content of the XML file. 如果我在IE中按CTRL + F5,则它可以正常工作,并且div具有XML文件的内容。 I'm using IE 9. 我正在使用IE 9。

Any ideas? 有任何想法吗?

Thanks in advance! 提前致谢!

Try this: 尝试这个:

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

This will tell you that the load is complete. 这将告诉您加载已完成。 Try checking the network tab in the Chrome developer tools afterwards to see if it was even pulled down. 之后,尝试检查Chrome开发者工具中的“网络”标签,以查看是否被拉下。

Update: 更新:

Instead of using the load method, try pulling it down with the AJAX method: 而不是使用load方法,请尝试使用AJAX方法将其下拉:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM