Quantcast
Channel: Rico's Tech Memo » javascript
Viewing all articles
Browse latest Browse all 2

jQuery 1.4.2 upgrade issue when doing json ajax calls

$
0
0

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. ]



Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images