ajax.reload() not working as per my requirement.

ajax.reload() not working as per my requirement.

saleemkhsaleemkh Posts: 6Questions: 1Answers: 0
edited September 2014 in Free community support

Hi,

Here's my code:

table = $('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url":"<?=base_url()?>customer/serverScript",
        "data":{
            "scope":scope,
            "service":service,
            "status":status,
            "inquiryfrom":$('#inquiryfrom').val(),
            "inquiryto":inquiryto
        }
    }
} );

Now when I use table.ajax.reload(), it sends the old 'inquiryfrom' value instead of getting the new one.

How can the 'data' be resubmitted with the reload()?

Thank you.

Answers

  • saleemkhsaleemkh Posts: 6Questions: 1Answers: 0
    edited September 2014

    Sorry guys!!!! I was using it wrong. Should have used it like this.

    table = $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url":"<?=base_url()?>customer/serverScript",
            "data": function(d){
                d.inquiryfrom = $('#inquiryfrom').val();
                d.inquiryto = $('#inquiryto').val();
                d.scope = $('#scope').val();
                d.service = $('#service').val();
                d.status = $('#status').val();
            }
        },
    } );
    
  • northamericannorthamerican Posts: 5Questions: 2Answers: 0

    i have an object like the one in your first example that i use in several places, including regular jquery ajax requests. having to do it the second way creates redundancy. is there a way to pass a plain object to data that will be rechecked when i call ajax.reload()?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Sure - ajax.data notes that you can use a plain object. However, if you want it to be evaluated on every submit (as would be the case for @saleemkh's code) you need to use it as a function.

    Allan

This discussion has been closed.