Jquery加载函数在firefox中引发“XML解析错误:格式错误”错误

时间:2017-12-08 06:38:57

标签: javascript jquery xml

尝试加载xml文件并获取xml解析错误。

{{1}}

不应该抛出任何错误。请注意,提供的网址有效,可直接从浏览器访问。该函数也被调用。不知何故,即使在控制台上报告错误后,页面也会成功加载。

不希望在控制台上看到任何错误。

2 个答案:

答案 0 :(得分:0)

我认为Firefox预计Content-Type和Chrome会忽略它。

$.ajax({
    url : "https://192.168.23.10/SystemServices/main?system:run=html/indicators/templates/editApp-definition.xml&Id=1000205&palletId=testtt",
    contentType: "text/xml",
    success : function(response) {
        $("#analyticForm_description").html(response);
    }
});

或对于加载方法使用ajaxSetup

  

描述:为将来的Ajax请求设置默认值。它的用途是   不推荐

$.ajaxSetup({
  contentType: "text/xml"
});

$("#analyticForm_description").load('https://192.168.23.10/SystemServices/...', function() { 
  MD.ui.editPallets.editform_definition();
});

答案 1 :(得分:0)

我也遇到了类似的错误,在搜索时我偶然发现了这篇文章,在调试代码一段时间后我找到了原因。

控制台显示错误

XML Parsing Error: undefined entity
Location: path-to-file.html#link3
Line Number 26, Column 29:

这就是我收到此错误的原因

我正在动态生成我想要点击的 url,并且由于一些拼写错误,我将 undefined 作为用于进行 ajax 调用的 url 导致此问题

$.ajax({
    url: url, //this was undefined
    type: "get",
    data: data,
    contentType: "text/xml",
    success: function (response) {
        //some code
    },
});

发布此信息可能会帮助面临同样问题的人。