Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 11 years ago

#4429 closed enhancement (fixed)

Use native JSON.parse if available inside ajax.httpData

Reported by: hakanson Owned by: flesler
Priority: minor Milestone: 1.4
Component: ajax Version: 1.3.2
Keywords: JSON Cc: hakanson, flesler
Blocked by: Blocking:


In jQuery.ajax.httpData, would you consider using the native JSON support (http://www.json.org/js.html) if available? Below is some untested sample code. Maybe the (JSON && JSON.parse) check is better located under jQuery.support.JSON and could be expanded to check if JSON.parse is a function?

// Get the JavaScript object, if JSON is used.

if ( type == "json" )
	if (JSON && JSON.parse)
		data = JSON.parse(data);
		data = window["eval"]("(" + data + ")");

Change History (5)

comment:1 Changed 14 years ago by flesler

Cc: hakanson flesler added
Resolution: invalid
Status: newclosed

We don't rely on this kind of things, only built-in browser features like querySelectorAll.

You can always add it for yourself using $.ajax's 'dataFilter' setting added since 1.3.

More here: http://dev.jquery.com/ticket/3231

comment:2 Changed 14 years ago by hakanson

Resolution: invalid
Status: closedreopened

Native JSON parse and stringify will be a built-in browser feature in Firefox 3.1 and IE8. That json.org link just referenced a compatible library. Sorry for the confusion, but I think it is a legitimate request and has a performance advantage.


comment:3 Changed 14 years ago by flesler

Owner: set to flesler
Status: reopenednew

Then we probably will add compatibility with it once it's established.

comment:4 Changed 14 years ago by john

Resolution: fixed
Status: newclosed

Fixed in SVN rev [6361].

comment:5 Changed 14 years ago by pbcomm

Line 503 of ajax.js should probably be changed to:

if ( type === "json" ) {

Note: See TracTickets for help on using tickets.