Will jQuery safely evaluate a JSON response to a HTTP POST?
Question
I couldn't find in the jQuery document if any of its AJAX methods SAFELY evaluates a JSON response to a $.post.
Solution
You can change the type
parameter on the $.post function:
$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
OTHER TIPS
jQuery's JSON eval is supposedly safe, and their $.getJSON method seems to work well. All you have to do is pass the "json" parameter to the $.post and it'll automatically parse the JSON. Like so:
$.post(url, data, callback, "json");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow