How to call a javascript function from a JSON string?
问题 If I do an AJAX post with jQuery that looks like $.post('MyApp/GetPostResult.json', function(data) { // what goes here? }); and the result looks like { "HasCallback": true, "Callback": "function(){ alert('I came from the server'); }" }; Then how do I call the Callback function? Can I just write if(data.HasCallback){data.Callback();} ? 回答1: This should work: function(data) { if(data.HasCallback) { eval(data.Callback); } } Edit: Didn't look quite carefully enough. If you're indeed getting the