I need to make a condition based on data returned from an ajax post outside the post function
function post(){
$.post('page.php',$('#form').serialize(), function(data) {
if(data !== 'good'){alert(data); return false;} // take this out of here
});
//and place it here
}
Code like below should work fine.
But remember that synchronous ajax call will freeze your page until request is done and you may find it better to find a way how to do what you need without moving
if(data !== 'good'){alert(data); return false;}outside success callback function.UPD: missed to specify request type, which should be
POSTinstead of defaultGET. Code updated.