📜 ⬆️ ⬇️

jQuery 1.3.x -> 1.4.x and JSON

This is not a post, but rather a memo for those who are faced with the problem of ajax and json, when switching to jQuery 1.4.
The new version uses built-in JSON parsing, and at the same time it becomes necessary to monitor its (json'a) correctness.
Examples of how to do it are not necessary:

{ 'qwe' : 'asd' }
{ "qwe" : 'asd' }
{ qwe: "asd" }
{ qwe: 'asd' }

i.e. such options now do not pass. It is necessary to use only double quotes!

{ "qwe" : "asd" }

If you are not able to make changes to server scripts, then on the client you can do a quick fix as follows:
')
$.ajax({
url: "/test.php",
dataType: "text",
success: function(data) {
json = eval("(" + data + ")");
// alert(json.success);
}
});

Perhaps someone will be useful. Thank you all, good luck to all!

Source: https://habr.com/ru/post/83892/


All Articles