繁体   English   中英

如何将成功函数中收到的数据响应发送回ajax的完整函数?

[英]How to send a data response received in success function back to ajax's complete function?

我有这样的代码:-

function fetch_chat_list(post_id)
{
  $.ajax({
    type:'POST',
    url: '<?php echo base_url();?>ajax-function',
    data: {'data':'chat',
         'id': post_id,
         'action': 'group'},
    dataType: 'json',
    success: function(data)
    {
        var id = data.id;
        var chat = data.chat;
    },
    complete: function() 
    {
      // Schedule the next request when the current one's complete
      setTimeout(fetch_chat_list(data.id), 25000);
    }
  });
}

我将成功响应返回到data的成功函数中。 它具有idchat

现在,在完成函数中,我想通过传递在success函数中收到的data.id再次调用fetch_chat_list()函数。

如何将data.id从success函数传递到complete函数?

使“ id”全局,而不是在成功块中声明它,这应该可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM