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

时间:2016-09-01 05:53:48

标签: javascript jquery ajax

我有一个像这样的代码: -

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

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

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

1 个答案:

答案 0 :(得分:0)

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

相关问题