Home > Uncategorized > jQuery 1.4.2 upgrade issue when doing json ajax calls

jQuery 1.4.2 upgrade issue when doing json ajax calls

The format requirement for ‘json’ dataType has changed slightly in the new jQuery 1.4.2: Double quotation marks are now a must (for both keys and values) to make ajax calls when specifying dataType: ‘json’ as the return data format. For example, the following json objects are no longer considered to be valid in jQuery 1.4.2:

{‘name’:’jQuery’}
{interest:’Programming’}
{‘balance’:443.25}

Attempting to use the above not-strictly-valid json data will result in success option (function) in the ajax() to give up quietly. [ My test result, which is different to what the $.ajax page (http://api.jquery.com/jQuery.ajax/) states:

In jQuery 1.4 the JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. (See json.org for more information on proper JSON formatting.)

]

It’s worth noting that 1.4.2 does not place a strict requirement on the json data being sent to the server, that is,
data: { userid: ‘Joe’, email: ‘joe@domain.com’ }
can still be used without causing problems.

[ edit: actually I was not correct about the last paragraph above – the “json data” being sent to the server is javascript object whose key should not be quoted. ]

Advertisements
Categories: Uncategorized Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: