I want to post data from a callback
function in jQuery:
// in my "index.php"
$.post('users.php', { user : the_users_name } ,function(data) {
$('body').html(data)
}
In the users.php
I want to post data to another script without loading the users.php
like below:
$.post('users2.php', { date_of_birth : $(".d_of_b_div").val() }
Now since users.php
is only called as a result of $.post
in index.php
, it doesn't post data to users2.php
.
How can I solve this problem? Or what am I missing out?
In your index.php
$.ajax({
url: 'users.php',
method: 'post',
data: { user : the_users_name },
success: function(data) {
$('body').html(data)
},
complete: function() {
// use complete callback to call users2.php
// this is only called after success and error callbacks are executed
$.post('users2.php', { date_of_birth : $(".d_of_b_div").val() });
}
});