Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 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:

Description

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);
	else 	
		data = window["eval"]("(" + data + ")");

Change History (5)

comment:1 Changed 11 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 11 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.

http://ajaxian.com/archives/native-json-in-firefox-31-joins-ie-8

comment:3 Changed 11 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 11 years ago by john

Resolution: fixed
Status: newclosed

Fixed in SVN rev [6361].

comment:5 Changed 11 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.