Is this a valid jquery callback function call?

微笑、不失礼 提交于 2019-12-01 14:12:01

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

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.

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.

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
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!