javascriptjqueryajaxdjangoreal-time-updates

Refreshing Ajax Pagination instance with new data in Django


how to reload my table and save the current positions page in the pagination in Django? I write one script with ajax for reloading my HTML file but my pagination crashed.

How to save current page in my JQuery file? this is my jquery file:

function refresh() {
    $.ajax({
        url: "/fax/fax_out_ajax/", // My url to need for reloading
        success: function(data) {
            $('#AliReload').html(data);
        }
    });
    setInterval("refresh()", 3000); // reload in your time, per 1000 = 1s
}

$(function(){
    refresh();
});

how to pass a number of the page from HTML to javascript?


Solution

  • If you already have the page number, say 5, pass it in after your url param:

    url: "/fax/fax_out_ajax/",
    data: {'page': 5},
    

    If you have the page number in the variable pageNumber, do:

    url: "/fax/fax_out_ajax/",
    data: {'page': pageNumber},
    

    If you don't already have the page number, get it from somewhere else on the page:

    url: "/fax/fax_out_ajax/",
    data: {'page': $('#page_number').val()},