Skip to content
Advertisement

How to send current page number in Ajax request

I am using jQuery DataTable to display huge amount of data in a table. I am getting data page wise on Ajax request like this:

JavaScript

and here is the spring controller:

JavaScript

The problem is that when I change page in table it alerts correct pageNo on page (in JavaScript), but in spring controller I am always getting the initial value assigned to the variable pageNo and not the current page number.

How do I pass pageNo dynamically to spring controller? Any help is appreciated.

Edit:

I updated JavaScript like this:

JavaScript

But it’s giving me an error:

DataTables warning: table id=propertyTable – Cannot reinitialise DataTable.

Advertisement

Answer

DataTables already sends parameters start and length in the request that you can use to calculate page number, see Server-side processing.

If you still need to have the URL structure with the page number, you can use the code below:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement