javascriptjqueryajaxasp.net-mvc

jquery and ajax request


I have js function which sends ajax request to the controller and succ. return result and append that result into desired div inside partial page. Now I want to implement pagination and I'm using $("#dataList").on("click", ".pagedList a".getPage); to listen when user click on pagination links to determine which page number is clicked

var getPage = function () {
    var $a = $(this);
    GetTabData(a);
    return false;
}

and finally I'm sending pagenumber to the next function which sends pagenumber together with activeTab variable to the controller

function GetTabData(xdata, pageNumber) {
    $.ajax({                    
        url: ('/Home/GetTabData'),
        type: 'POST',
        contentType: 'application/json',
        dataType: 'html',
        data: JSON.stringify({ activeTab: xdata, page: pageNumber }),
        success: function (result) {
            $("[id^='tab-'] div").remove();
            var currentTab = $("#tab-" + xdata).html(result);
        },
        error: function () { alert("error"); }
    });
}

Something is definit. wrong here cause on controller side I'm using

Request.IsAjaxRequest()

to allow only ajax request to paginate data and I'm getting Not ajax request. Once more, If I remove pagination option completly and send just activeTab everything works.

Any thoughts?


Solution

  • Your GetTabData function takes 2 arguments: xdata and pageNumber but when calling it you are passing only one:

    var $a = $(this);
    GetTabData(a);
    

    So you probably are getting a javascript error and the return false statement is never reached.