Is this a valid jquery callback function call?

前端 未结 4 515
庸人自扰
庸人自扰 2021-01-16 17:34

I executing a function like this,



        
相关标签:
4条回答
  • 2021-01-16 18:09

    The callback of the pagination plugin here which I assume you are using is defined internally as

    opts.callback(current_page, containers);
    

    This is different to the signature of your callback so no it will not work the same.

    0 讨论(0)
  • 2021-01-16 18:24

    Apparently the currentPage parameter of getEntities() is an object, so adding 1 to it is not a sensible operation. Check with firebug what the type and contents of currentPage is.

    0 讨论(0)
  • 2021-01-16 18:27

    The getEntities function expects 3 arguments. Here you are passing only 2:

    callback: getEntities("Clients/GetClients", formatClientsResult)
    

    Also the second argument needs to be an integer and not another function. And as it is a callback it needs to be defined as such:

    callback: function() {
        getEntities("Clients/GetClients", 0, formatClientsResult);
    }
    

    UPDATE:

    The reason you are always getting the same AJAX request is that you always pass 0 to the getEntities function in the pagination callback.

    Try this:

    $(".pager").pagination(maxvalues, {
        callback: function (new_page_index, pagination_container) {
            // Notice how the new_page_index is passed
            getEntities("home/GetClients", new_page_index, formatClientsResult);
        },
        current_page: 0,
        items_per_page: 5,
        num_display_entries: 5,
        next_text: 'Next',
        prev_text: 'Prev',
        num_edge_entries: 1
    });
    
    0 讨论(0)
  • 2021-01-16 18:31

    Try this:

        $(document).ready(function() {
            var helper = function() {
                getEntities("Clients/GetClients", 0, formatClientsResult);
            };
            helper();
            var maxvalues = $("#HfId").val();
            $(".pager").pagination(maxvalues, {
                callback: helper,
                current_page: 0,
                items_per_page: 5,
                num_display_entries: 5,
                next_text: 'Next',
                prev_text: 'Prev',
                num_edge_entries: 1
            });
    
    0 讨论(0)
提交回复
热议问题