Skip to content Skip to sidebar Skip to footer

Firefox Json "not Well Formed" Errror On Valid Json

I'm receiving the following error message in Firefox: Error: not well-formed Source File: http://school/courses.booking.add.php?1287657494723 Line: 1, Column: 1 Source Code: {'type

Solution 1:

It seems that the javascript debugger in the Web Developer Toolbar simply expects all Ajax responses to be XML, regardless of the MIME type. Anything else will produce a "not well formed" error.

Solution 2:

I had the same issue using OpenJS's jxs. What was causing the error, in this case, was this conditional in the load property (line 33 in version 3.01.A):

//XML Format need this for some Mozilla Browsers
if (http.overrideMimeType) http.overrideMimeType('text/xml');

It made the browser always expect for XML. That can be easily fixed by this:

// XML Format needs this for some Mozilla Browsersif (format.charAt(0) === "x" && http.overrideMimeType) http.overrideMimeType("text/xml");

Since it now makes a comparison of format, the code should also have its place changed and should be put after

format = format.toLowerCase();

Which is currently at line 38. So, the code goes from:

32 //XML Format need this for some Mozilla Browsers
33if (http.overrideMimeType) http.overrideMimeType('text/xml');
3435if(!method) method = "GET";//Default method is GET
36if(!format) format = "text";//Default returntypeis'text'37if(!opt) opt = {};
38format = format.toLowerCase();
39 method = method.toUpperCase();

To:

32if(!method) method = "GET";//Default method is GET
33if(!format) format = "text";//Default returntypeis'text'34if(!opt) opt = {};
35format = format.toLowerCase();
36 method = method.toUpperCase();
3738 //XML Format need this for some Mozilla Browsers
39if (format.charAt(0) === "x" && http.overrideMimeType) http.overrideMimeType("text/xml");

Solution 3:

I had this issue with previous versions of FireFox + FireBug where there existed newlines in front of/after the JSON formatted content. Make sure you clear your output stream before outputting JSON responses on the server side.

JSP example:

out.clear(); out.println(json);

Post a Comment for "Firefox Json "not Well Formed" Errror On Valid Json"