jQuery wait for ajax call to be over before continuing
Posted
by Flo
on Stack Overflow
See other posts from Stack Overflow
or by Flo
Published on 2010-04-13T16:20:12Z
Indexed on
2010/04/13
16:23 UTC
Read the original article
Hit count: 222
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;
}
© Stack Overflow or respective owner