简体   繁体   中英

jquery post call and reloading after every 5 seconds

I am doing the ajax functionality where what i want is, after every successful ajax call, the div should get refreshed.

Currently i am considering of using setTimeout but not sure how to proced ahead

Here is my curret code

$(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>

i want to refresh the reloadcounters after the result set

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
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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