[英]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
的成功函数中。 它具有id
和chat
。
现在,在完成函数中,我想通过传递在success
函数中收到的data.id
再次调用fetch_chat_list()
函数。
如何将data.id从success
函数传递到complete
函数?
使“ id”全局,而不是在成功块中声明它,这应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.