Reputation: 7721
I have noticed that XMLHttpRequest in my Firefox addon logs an error processing xyz.json if content is an array. The error does not halt the execution (hence a minor bug)
Example of xyz.json:
[
"string1",
"string2",
"string3"
]
Although above is a valid JSON, XMLHttpRequest logs a syntax error at [
It is possible to avoid the error logging by setting responseType to 'text'.
Is this limited to Firefox Addon or Firefox or JavaScript in general?
Upvotes: 1
Views: 73
Reputation: 33162
Firefox will consult the response MIME type to see if the response should be parsed as XML. Reading some file:
, chrome:
, resource:
, etc. that does not provide a response MIME type will make XHR default to XML (backwards-compatibility; after all the XML is right in the name), and attempt to parse it to provide .responseXML
. This will of course fail if the file does not contain XML, and hence the warning.
Use .overrideMimeType()
to provide an explicit proper MIME type, or just text/plain
if in doubt, to stop XHR from attempting to parse data as XML, and the message will go away.
Upvotes: 2