console reports syntax error for valid json fetched via jquery.ajax

NEW
Unassigned

Status

()

Firefox
Developer Tools: Console
3 years ago
9 months ago

People

(Reporter: shaver, Unassigned)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

981 bytes, application/vnd.mozilla.xul+xml
Details
97 bytes, text/plain
Details
I have the following content a JSON file:

------
[
  {"author": "Pete Hunt", "text": "This is one comment"},
  {"author": "Jordan Walke", "text": "This is *another* comment, wow"}
]
------

When it's loaded via $ajax, I get an error in the console:

syntax error comments.json:1

The file seems to be parsed correctly nonetheless, and JSON.parse from the console correctly decodes it.

Chrome doesn't report an error here.

Nightly of 6-27 vintage.
This sounds like a problem with $ajax. Is that jquery? Try debugging the library, see what triggers the error.

Comment 2

3 years ago
This is not jquery, nor custom library-specific. I'm uploading an .xul and a json file to demonstrate the problem. The issue still exists in Firefox 33.

Comment 3

3 years ago
Created attachment 8516471 [details]
loadJsonFile.xul

Comment 4

3 years ago
Created attachment 8516472 [details]
aFile.txt

Comment 5

2 years ago
The error appears also when we open a json file using XMLHttpRequest
------
var req = new XMLHttpRequest();
req.open('GET', "file.json", false); 
req.send(null);
if((req.status == 200) || (req.status == 304) ) {
  return(JSON.parse(req.responseText));
------

My file "file.json" contains:
------
[
    {
        "firstName": "John",
        "lastName": "Doe"
    },
    {
        "firstName": "Anna",
        "lastName": "Smith"
    }
]
------

On the console log: syntaxe error file.json:1:1

Firefox 36.0.1 on Linux/manjaro

Comment 6

2 years ago
What is the value of the "Content-Type" header being returned from the server? If I had to take a guess, it isn't being set, and Firefox is likely defaulting the content type to "text/xml". Since the content type is json and not xml, the xml parser cannot parse it and it results in "Syntax error" being written to the console.

Try setting the content type on the server to "application/json" or "text/plain" and see if the syntax error still occurs.

Comment 7

2 years ago
confirm at version 41.0
the content-type from server header is 

Content-Type:"application/json;charset=UTF-8"

already. at chromium work fine.

just try, about few second.. why still after year...

Comment 8

2 years ago
(In reply to arliweng from comment #7)
> confirm at version 41.0
> the content-type from server header is 
> 
> Content-Type:"application/json;charset=UTF-8"
> 
> already. at chromium work fine.
> 
> just try, about few second.. why still after year...

that r not json string or prase problem, because work fine when i use that string for JSON.parse in the console, but sohw me error in the developer tools-network-response.

Comment 9

2 years ago
fixed @ version 41.0.1

Comment 10

2 years ago
(In reply to arliweng from comment #9)
> fixed @ version 41.0.1

update: still when unknown reason. but when i reopen developer tools, that problem gone.

Comment 11

a year ago
Bug still exists in 46.0 and it's really very simple.

Content-Type: "application/json;charset=UTF-8"
- cause "syntax error" message at  json 1:1, but all work fine except message


Content-Type:"application/json;charset=UTF-8"
- all ok.

Yes, it's just one space
Whiteboard: [platform-rel-jQuery]

Updated

10 months ago
platform-rel: --- → ?
platform-rel: ? → ---
Whiteboard: [platform-rel-jQuery]
You need to log in before you can comment on or make changes to this bug.