Skip to content Skip to sidebar Skip to footer

How Pass Dom Element Value To Ajax Request (html.pagedlist Parameters)

I am learning ajax requests and I was wondering if I am doing right here. Well I have a page which include pagination, sorting and searching. I am trying to get this by ajax becaus

Solution 1:

My answer here will help you: https://stackoverflow.com/a/50727347/177416

You want to capture the user's clicking of a page number in the pager control and rewrite the link before letting it through. This is done on the client via JavaScript onClick handler on the page numbers; the following handler goes in your jQuery document ready event handler:

$('#pager').find('a[href]').on('click', function (e) {
    e.preventDefault();
    location.href = this.split('?')[0]
        + "?page=" + getQueryStringValue(this, 0).replace('page=','') 
        + "&sortOrder=" + $("#sortOrder").val(); // Add other values if needed
    }
});

Here's the helper function:

getQueryStringValue: function (anchor, index) {
    var queryString = $(anchor).attr('href').split('?')[1];
    var values = queryString.split('&');
    returnvalues[index];
}

This line gets us the raw URL without the querystring; this in this case is the URI:

this.split('?')[0]

Setting location.href is like clicking a link; it'll redirect the page to the indicated URI.

Post a Comment for "How Pass Dom Element Value To Ajax Request (html.pagedlist Parameters)"