I have a javascript function that calls a generic function to call ajax to a server. I need to get the result (true / false) from the ajax callback function, but the result I get is always "undefined".
A super simplified version of a common function without my logic would be:
function CallServer(urlController) { $.ajax({ type: "POST", url: urlController, async: false, data: $("form").serialize(), success: function(result) { if (someLogic) return true; else return false; }, error: function(errorThrown) { return false; } }); }
And the function calling it will look something like this:
function Next() { var result = CallServer("/Signum/TrySave"); if (result == true) { document.forms[0].submit(); } }
The variable "result" is always "undefined", and debugging it, I see that the line "return true" of the callback function is executed.
Any ideas why this is happening? How could I call the return value from the CallServer callback?
thanks
javascript jquery ajax
antonioh
source share