Reload ajax with parameters

Reload ajax with parameters

aurelienaurelien Posts: 2Questions: 1Answers: 0

Hello,

I'm trying to implement a search form. The goal is to refresh datatable automatically.
Here is my code:

var table = $('#tableRapport').DataTable({
    "ajax": {
        "url": $('#urlRecherche').text(),
        "type": "POST",
        "data": { 
            dateDeb: $('#dateDeb').val(),
            dateFin: $('#dateFin').val(),
        },
    },
});

$('#dateDeb, #dateFin').change(function() {
    table.ajax.reload();
});

The problem is here:

    dateDeb: $('#dateDeb').val(),
    dateFin: $('#dateFin').val(),

When I call the "reload" function, fields are not updated with "val ()".

A solution?

Thanks

This question has an accepted answers - jump to answer

Answers

  • DaimianDaimian Posts: 62Questions: 1Answers: 15
    Answer ✓

    When declaring the AJAX data fields use functions, for example:

    ajax: {
     url: 'url.php',
     type: 'POST',
     data: {
      dateDeb: function() { return $('#dateDeb').val() },
      dateFin: function() { return $('#dateFin').val() }
     }
    }
    
  • aurelienaurelien Posts: 2Questions: 1Answers: 0

    Hello,

    Oh yes! It works ;)

    Thanks!

This discussion has been closed.