jquery ajax 请求 xml 资源在 Firefox 中产生 "not well-formed" 错误

jquery ajax request to xml resource yields "not well-formed" error in Firefox

我知道这个问题已经被问过很多次了,但是那里给出的答案对我不起作用。

我想我正在做一个非常常见的请求来获取 xml 资源:

$(document).ready(function() {
    $.ajax({
      type: "GET",
      url: "data.xml",
      dataType: "xml",
      success: function(xml) {
        $(xml).find("main").each(function() {
          alert($(this).attr("val"));
        });
      }
    });

可以找到完整的文件 here, and the xml resource here

当我使用 Firefox 36.0.4 访问它时,我收到了预期的“hello world”警报,但 javascript 控制台列出了错误:

http://esel7353.org/ : Unable to run script because scripts are blocked internally.

not well-formed :1:76

在此处提出的许多问题中,响应中的内容类型 header 不准确,但在我的情况下,服务器告诉 firefox,data.xml 是 application/xml。

此外,mimeType 选项也无济于事。

我还制作了一个干净的 FF 配置文件,以确保这不是由插件引起的,但错误消息仍然存在。

我在 中写了这个 - 但由于您的问题也没有得到解答,我也会 post 在这里。


我不能肯定地说它会解决您的问题,但我在 firefox 中遇到了类似的 'not well-formed' 消息问题。原来 jQuery 1.11.2 和 1.11.3 中存在一个错误 - https://github.com/jquery/jquery/issues/1969 - 已在上游修复。

如果您在您的服务器上托管 jquery,这是一个相对较小的变化 - 请参阅 github commit

在 jquery.1.11.3.js 行 cca 1197(在 QSA/matchesSelector 部分):

 -              "<select id='" + expando + "-\f]' msallowcapture=''>" +
 +              "<select id='" + expando + "-\r\' msallowcapture=''>" +

希望很快会有新版本。