Side navigation
#13430 closed bug (duplicate)
Opened February 11, 2013 04:27AM UTC
Closed September 24, 2013 01:19PM UTC
Error in parseJSON:
Reported by: | odesuk@yahoo.com | Owned by: | odesuk@yahoo.com |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | ajax | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I had to update code to fix this issue for me.
LIne 548 in jquery-1.9.1.js
Error in IE 10: Invalid character
Added check for null & undefined before calling window.JSON
if (data === null || data === undefined) {
return data;
}
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );
}
...
Attachments (0)
Change History (11)
Changed February 11, 2013 04:31AM UTC by comment:1
Changed February 11, 2013 04:31AM UTC by comment:2
owner: | → odesuk@yahoo.com |
---|---|
status: | new → pending |
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.
To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.
Also, please read: http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/
Changed February 14, 2013 09:36AM UTC by comment:3
It's really as simple as typing
$.parseJSON("");
or
$.parseJSON(undefined);
in web console (of Chrome 24.0.1312.57 m or Firefox 21.0a1, both on Windows in my case).
Edge and 1.9.0 are affected.
Changed February 14, 2013 01:36PM UTC by comment:4
resolution: | → notabug |
---|---|
status: | pending → closed |
Ok then, there is your problem. An empty string or undefined
are not valid JSON. The jQuery Migrate plugin catches these things for you, and will even fix them if you don't want to change code right now:
Changed February 14, 2013 02:02PM UTC by comment:5
Ok, but API docs still state:
"Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON."
Which is kind of misleading.
Changed February 14, 2013 02:09PM UTC by comment:6
Agreed. There's a docs ticket open to fix that. Note that it does say the method takes a string, and that it takes a JSON string. Unfortunately someone documented the incorrect behavior at some point.
Changed April 10, 2013 05:07AM UTC by comment:8
Is not bug jQuery.
if ( window.JSON && window.JSON.parse ) { JSON.parse_original = JSON.parse; JSON.parse = function(data){ return (data == "") ? {} : JSON.parse_original(data); } }
Changed September 24, 2013 01:18PM UTC by comment:10
resolution: | notabug |
---|---|
status: | closed → reopened |
Changed September 24, 2013 01:19PM UTC by comment:11
component: | unfiled → ajax |
---|---|
resolution: | → duplicate |
status: | reopened → closed |
Duplicate of #13169.
#13431 is a duplicate of this ticket.