“not well-formed” error in Firefox when loading JSON file with XMLHttpRequest

前端 未结 8 2274
青春惊慌失措
青春惊慌失措 2020-11-28 09:57

I\'m getting a \"not well-formed\" error in the error console of Firefox 3.0.7 when the JavaScript on my page loads a text file containing an object in JavaScript Object Not

8条回答
  •  执念已碎
    2020-11-28 10:22

    Kent, I disagree.

    The following IS "valid" JSON:

    { a: 3 }
    

    JavaScript object property names do NOT have to be strings.

    The problem is one of MIME type, not JSON/JavaScript syntax.

    I just solved this very issue by adding json as "text/javascript" to my webserver mime types file:

    text/javascript                 js, json
    

    The "not well-formed" error disappeared. The browser (FireFox) assumed, incorrectly, that the .json file was XML.

提交回复
热议问题