【问题标题】:Issue loading XML into DIV using JavaScript in IE在 IE 中使用 JavaScript 将 XML 加载到 DIV 中的问题
【发布时间】:2012-12-14 00:07:23
【问题描述】:

我需要将配置 XML 加载到 DIV 中,为此我使用以下代码:

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

这段代码在 Chrome 中可以正常工作,但在 IE 中却不行。它在控制台中打印“文档准备就绪”,但“footer_config”DIV 为空。如果我在 IE 中按 CTRL+F5 它可以工作,并且 div 具有 XML 文件的内容。我使用的是 IE 9。

有什么想法吗?

提前致谢!

【问题讨论】:

  • 你试过没有console.log吗?
  • 是的,一开始它没有console.log,我把它放在那里检查$(document).ready是否正在执行。

标签: javascript jquery xml load internet-explorer-9


【解决方案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();
}});

【讨论】:

  • 究竟如何检查 Internet Explorer 中的 Chrome 开发人员工具,因为它是唯一失败的浏览器?
  • 您可以查看服务器日志以查看该 URL 是否被访问。
  • 我尝试使用 console.log('Load finished')。它打印“加载完成”,但不会将 XML 加载到 DIV 中。这仅在页面被缓存时发生。如果我清理缓存,DIV 将加载 XML
  • 对不起,我指的是 IE 中的 F12 开发者工具。
  • 谢谢!这就是我解决它的方法,进行 ajax 调用并将“缓存”设置指定为 false。感谢您的帮助。
猜你喜欢
  • 2011-01-20
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 2012-09-04
  • 2023-03-09
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
相关资源
最近更新 更多