views:

430

answers:

2

I couldn't find in the jQuery document if any of its AJAX methods SAFELY evaluates a JSON response to a $.post.

+1  A: 

You can change the type parameter on the $.post function:

$.postJSON = function(url, data, callback) {
    $.post(url, data, callback, "json");
};
CMS
Haha, I copied from the exact same feature request. Great minds think alike :P
Salty
A: 

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");
Salty
as safe as eval gets yeah;)
redsquare