从回调函数中发布数据


JQuery Post data from callback function

我想在jQuery中发布callback函数的数据:

// in my "index.php"
$.post('users.php', { user : the_users_name } ,function(data) {
    $('body').html(data)
}

users.php中,我想将数据发布到另一个脚本而不加载users.php,如下所示:

$.post('users2.php', { date_of_birth : $(".d_of_b_div").val() }      

现在,由于users.php仅作为index.php中的$.post的结果而被调用,因此它不会将数据发布到users2.php

我该如何解决这个问题?或者我错过了什么?

在你的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() });
  }
});