2011-10-04 56 views
11

我使用jQuery的Ajax像下面良好的Chrome:
XML解析错误:没有很好地形成,在FireFox但

$.ajax({ 
url: 'servlet/*****Servlet', 
     dataType: "text", 
     success: function(data) { 
     var subareaCoordsPGs = preprocessCoords(data); 
     } 
    }); 

它的工作好,甚至我没有设置在Chrome中的数据类型,但它失败带有XML解析错误的FF。

Response Headersview source
Server Apache-Coyote/1.1
Transfer-Encoding chunked
Date Tue, 04 Oct 2011 00:08:08 GMT
Request Headersview source
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 5.2; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept text/plain, /; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost:8080/
*/
Cache-Control max-age=0

XML Parsing Error: not well-formed Location: moz-nullprincipal:{2f6a8381-b987-448b-88c2-e89c4e13440b} Line Number 1, Column 4:

[email protected] -33.9353900931769,151.247877472978 -33.9360784582012,151.24...
------^

搜索后,我知道这是好事,设置正确的数据类型,我希望它被解析就像普通的文本,但为什么在FF 智能猜没有作品,哪怕我设置它的类型“文字”明确吗?

+1

请注意,即使您收到此消息,您的成功呼叫可能会触发该数据。最新版本的Firefox可能会抱怨,但仍然会继续,或者至少在我的情况下,Firefox 55已经做到了。这个错误信息对我来说是一段红鲱鱼,因为我认为它是致命的。 –

+0

@ J.Allen:我面临同样的问题。我在最新版本的Firefox中看到了这个问题。任何想法来解决它? – santoshM

回答

16

你的服务器没有返回一个内容类型,所以Firefox假定这是_XML_HttpRequest,你的响应可能是XML并试图解析它。当失败时,它会停止尝试并报告这毕竟不是XML。

Chrome可能会做同样的事情,但不会报告任何内容。

我建议实际发送一个Content-Type标题,指明你的数据是什么。

+0

感谢您的提示。我使用jQuery Ajax设置了Content-Type text/plain; charset = UTF-8,如设置参数contentType:“text/plain; charset = UTF-8”,它仍然适用于Chrome,但不适用于FireFox – qc999

+0

@ qc999我不知道jQuery的功能。它是否在XHR对象上调用overrideMimeType? –

+0

@ Boris Zbarsky我已经检查过FireBug的请求头,它看起来像这样:Host:localhost:8080 User-Agent:Mozilla/5.0(Windows NT 5.2; WOW64; rv:7.0.1)Gecko/20100101 Firefox /7.0.1 接受:text/plain,*/*; q = 0.01 Accept-Language:zh-cn,en; q = 0.5 Accept-Encoding:gzip,deflate Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7 Connection:keep-alive Content-Type:text/plain; charset = UTF-8 X-Requested-With:XMLHttpRequest所以我假设它已经覆盖内容类型。但仍然有相同的XML解析问题。 – qc999

相关问题