I have for eg code like this
function check(parameters){
some code;
$.post('/url', function(data) {
//and here I want if data==0 return false from function check
//if no go and skip to instruction 1
});
instruction 1;
}
I want in my program later to use if(check(params)==0) but it doesn’t seems to working.
How i can do this in java script? I need to do if($.post…==0)?
Best regards
Ajax is asynchronous, if you want to be synchronous you can use the setting in the ajax method. With an asynchronous request, you can provide a callback function. The callback function will then be run when the ajax message returns.
You could call your check function like this, with a callback function after params.
And the run the callback in
checkwhen the ajax message returns.