I have a jquery function, doing a $.post of a value to a php function. This php function then puts this value in the $_SESSION and shows the appropriate content.
I would like that the execution does not continue until the post is completed, since after the $.post the content is shown, and the new $_SESSION value does not take effect until the next refresh.
How can I do this?
Thanks!
That's what callbacks are for. Pass a function to one of the $.post()
parameters and it will be executed only when the request is successful:
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});
document.write('This won`t wait for ajax');
this code will execute the alert()
part only after the ajax request ends loading, but document.write()
will execute straight away, without waiting for a response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With