Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  35] [ 7]  / answers: 1 / hits: 16861  / 13 Years ago, thu, march 31, 2011, 12:00:00

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();} ?


More From » jquery

 Answers
5

This should work:



function(data) {
if(data.HasCallback) {
eval(data.Callback);
}
}


Edit: Didn't look quite carefully enough. If you're indeed getting the function() { ... } text, then you need to eval(data.Callback + ()).


[#93002] Tuesday, March 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
siena

Total Points: 199
Total Questions: 91
Total Answers: 91

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;