Google returns Unparsable Cuft to the json response like this:
throw 1; <dont be evil> { foo: bar}
- My current web applications use jQuery.Ajax to retrieve JSON data. How should they be modified to consume valid data?
Here is a relevant demo
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should probably remove the beginning part from the response:
UPDATE:
To make the re-writing available in every Ajax call you could also register a global Ajax Converter in jQuery:
You will still need to specify your defined
dataTypein the request options.UPDATE 2:
If you need to tweak your existing calls to do the response cleanup automatically, you could patch jQuery’s
ajaximplementation to automatically use your converter in certain situations:
Note that this redefinition has to included after loading jQuery and before the first Ajax call is made. You may also need to consider that
$.ajaxcan also be called without a separateurlparameter…