jQuery wait for ajax call to be over before continuing
- by Flo
Hi all,
I have a problem with a jQuery ajax call.
I need to wait for the call to be finished in order to return a value.
However, the script seems to jump ahead and not wait for the call to be over.
my function then returns "undefined".
I have tried to use the .ajax() method and set the value of async to false, but this would not work either.
I could I get my function to return the value that I could through the ajax call?
Thank you!
Here is the code:
function get_rsrce_name(){
jQuery.post(
'<?php echo admin_url( 'admin-ajax.php' ); ?>',
{ action :'my_action', option_rsrce : 'option_rsrce' },
function( data ) {
output = data.option_name;
},
"json"
);
return output;
}