Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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
Javascript jquery post调用并在每5秒后重新加载_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript jquery post调用并在每5秒后重新加载

Javascript jquery post调用并在每5秒后重新加载,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在做ajax功能,我想要的是,在每次成功的ajax调用之后,div应该得到刷新 目前我正在考虑使用setTimeout,但不确定如何提前处理 这是我的密码 $(document).on('click','.openbrand',function(e) { var id = $(this).attr('data-id'); var name = $(this).attr('data-rel'); var data = 'name='+name+'

我正在做ajax功能,我想要的是,在每次成功的ajax调用之后,div应该得到刷新

目前我正在考虑使用setTimeout,但不确定如何提前处理

这是我的密码

$(document).on('click','.openbrand',function(e) {
        var id = $(this).attr('data-id');
        var name = $(this).attr('data-rel');
        var data = 'name='+name+'&id='+id;
        $.post("update.cfm",{id:id,brand:name},function(data, textStatus, jqXHR){

        });
    });

 <div class="reloadcounters" style="float:right; padding:10px; position:absolute;"><a href="javascript:void(0);">#fans#</a> <i style="cursor:pointer;" data-rel="#brand#" data-id="#id#" class="fa fa-heart-o openbrand"></i></div>

我想在结果集之后刷新重载计数器

我不认为问题标题实际上是指每5秒一次:我在每次单击后5秒阅读问题。但这是我在每5秒阅读后的理解,我们将看到,但我认为这只是语法错误:我认为我的问题没有正确阅读,我希望id为:reloadcounters的div在evry更新后重新加载,或者说5秒,你给我的代码实际上更新了操作页面,这在屏幕上永远看不到。代码预计不会按原样工作,在setTimeout之前,在刷新函数中,你应该将实际刷新内容的代码,我不知道它应该是什么样子,但我认为它是与回调函数一起出现的,不是吗?
function refresh(){
    $.post("update.cfm",{id:id,brand:name},function(data, textStatus, jqXHR){
       setTimeout(function(){refresh();}, 5000);
    });
}


$(document).on('click','.openbrand',function(e) {
        id = $(this).attr('data-id');
        name = $(this).attr('data-rel');
        data = 'name='+name+'&id='+id;
        refresh();
        document.unbind("click"); //Optional, do not know if needed
    });