XML Parsing Error: not well-formed in FireFox but good in Chrome
I using jQuery Ajax like below:
$.ajax({
url: 'servlet/*****Servlet',
dataType: "text",
success: function(data) {
var subareaCoordsPGs = preprocessCoords(data);
}
});
it works good even i did not set the dataType in Chrome, however, it failed in FF with XML parsing error.
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 开发者_如何学GoFirefox/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=0XML Parsing Error: not well-formed Location: moz-nullprincipal:{2f6a8381-b987-448b-88c2-e89c4e13440b} Line Number 1, Column 4:
534@151.248078368847 -33.9353900931769,151.247877472978 -33.9360784582012,151.24...
------^
after searched, i know it is good to set the proper data type, i want it to be parsed just as normal text, but why Intelligent Guess not works in FF, even i set it's type is "text" explicitly?
Your server is not returning a content-type, so Firefox assumes that since this is _XML_HttpRequest your response might be XML and tries to parse it. When that fails, it stops trying and reports that this wasn't XML after all.
Chrome likely does the same but doesn't report anything.
I suggest actually sending a Content-Type header indicating what your data is.
Just Add this code. The problem is the server did not specify the mime type and firefox takes it to be xml. This code will specify what Mime type the xhr response is going to be.
beforeSend: function(xhr){ xhr.overrideMimeType( "text/plain; charset=x-user-defined" );},
精彩评论