title: How to send current page number in Ajax request
body: <p>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:</p>
  
  <pre><code>var pageNo = 1;
  $('#propertyTable').dataTable( {
      "processing": true,
      "serverSide": true,
      "ajax": "${contextPath}/admin/getNextPageData/"+pageNo+"/"+10,
      "columns": [
          { "data": "propertyId" },
          { "data": "propertyname" },
          { "data": "propertyType" },
          { "data": "hotProperties" },
          { "data": "address" },
          { "data": "state" },
          { "data": "beds" },
          { "data": "city" },
          { "data": "zipCode" }
      ],
      "fnDrawCallback": function () {
          pageNo = this.fnPagingInfo().iPage+1;
          alert(pageNo); // this alerts correct page
       }
  } );
  </code></pre>
  
  <p>and here is the spring controller:</p>
  
  <pre><code>@RequestMapping(value="/getNextPageData/{pageNo}/{propertyPerPage}")
  public @ResponseBody PropertyDatatableDto getNextPageData(@PathVariable Integer pageNo, @PathVariable Integer propertyPerPage) {
      System.out.println("called");
      System.out.println(pageNo); // this always prints 1, what i need is current pageNo here
  
  
      PropertyDatatableDto datatableDto = new PropertyDatatableDto();
      //datatableDto.setDraw(1);
      datatableDto.setRecordsTotal(100);
      datatableDto.setRecordsFiltered(100);
      datatableDto.setData(adminService.getAllPropertyList());
      return datatableDto;
  }
  </code></pre>
  
  <p>The problem is that when I change page in table it alerts correct <code>pageNo</code> on page (in JavaScript), but in spring controller I am always getting the initial value assigned to the variable <code>pageNo</code> and not the current page number.</p>
  
  <p>How do I pass <code>pageNo</code> dynamically to spring controller? Any help is appreciated.</p>
  
  <h2>Edit:</h2>
  
  <p>I updated JavaScript like this:</p>
  
  <pre><code>    var oSettings = $('#propertyTable').dataTable().fnSettings();
      var currentPageIndex = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; 
  
  $('#propertyTable').dataTable({
      "processing": true,
      "serverSide": true,
      "ajax": "${contextPath}/admin/getNextPageData/"+currentPageIndex+"/"+10,
      "columns": [
          { "data": "propertyId" },
          { "data": "propertyname" },
          { "data": "propertyType" },
          { "data": "hotProperties" },
          { "data": "address" },
          { "data": "state" },
          { "data": "beds" },
          { "data": "city" },
          { "data": "zipCode" }
      ]
  });
  </code></pre>
  
  <p>But it's giving me an error: </p>
  
  <blockquote>
    <p>DataTables warning: table id=propertyTable - Cannot reinitialise DataTable.</p>
  </blockquote>