Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在ajax响应中发出jquery ajax请求吗?_Jquery - Fatal编程技术网

我可以在ajax响应中发出jquery ajax请求吗?

我可以在ajax响应中发出jquery ajax请求吗?,jquery,Jquery,根据ajax调用的响应,我想进行几个ajax调用 像这样的 $.post('test1.php', function(res) { var processid = res.processid; $.post('test2.php', id : processid, function (data){ // do some stuff and make other ajax calls }); },'json') 这是正确的吗?我需要根据每个请求的响

根据ajax调用的响应,我想进行几个ajax调用

像这样的

$.post('test1.php', function(res) {

    var processid = res.processid;

    $.post('test2.php', id : processid, function (data){

        // do some stuff and make other ajax calls
    });

},'json')
这是正确的吗?我需要根据每个请求的响应提出其他请求


谢谢

是的,没错。第二次
POST
将在第一次完成后运行

或者,您可以使用jQuery的and创建一个队列,并使用来存储变量。你也可以使用AJAX队列插件(谷歌为他们提供),我没有使用任何插件,所以我不能推荐一个

//Add POST 1
$(document).queue('AJAX', function(next){
    $.post('test1.php', function(res){
        $(document).data('processid', res.processid); //We need to store this somewhere
        next(); //Call next queued function (if any)
    }, 'json');
});

//Add POST 2
$(document).queue('AJAX', function(next){
  $.post('test2.php', 'id='+$(document).data('processid'), function (data){
    next(); //Call next queued function (if any)
  });
});

// Start the queue
$(document).dequeue('AJAX');

是的,没错。第二次
POST
将在第一次完成后运行

或者,您可以使用jQuery的and创建一个队列,并使用来存储变量。你也可以使用AJAX队列插件(谷歌为他们提供),我没有使用任何插件,所以我不能推荐一个

//Add POST 1
$(document).queue('AJAX', function(next){
    $.post('test1.php', function(res){
        $(document).data('processid', res.processid); //We need to store this somewhere
        next(); //Call next queued function (if any)
    }, 'json');
});

//Add POST 2
$(document).queue('AJAX', function(next){
  $.post('test2.php', 'id='+$(document).data('processid'), function (data){
    next(); //Call next queued function (if any)
  });
});

// Start the queue
$(document).dequeue('AJAX');

谢谢你的快速回复。有没有更好的办法?或任何可用的库/插件,将我的requests@supa:有很多插件,只有谷歌的“Ajax队列”。我不使用任何一种,所以我不能推荐一种。我使用jQuery的
$.queue
$.dequeue
创建了一个ajax队列。感谢您的快速回复。有没有更好的办法?或任何可用的库/插件,将我的requests@supa:有很多插件,只有谷歌的“Ajax队列”。我不使用任何一种,所以我不能推荐一种。我使用jQuery的
$.queue
$.dequeue
创建了一个ajax队列。