Using two functions in data to pass via ajax

Using two functions in data to pass via ajax

mahmoodrmmahmoodrm Posts: 4Questions: 2Answers: 0

hello friends;
I need to define two functions in the datatables to pass two data through ajax as shown below but the problem is that this two functions are not working together but together not. when I uncomment line 12, the second function will work properly, and when I commenting the second function, the first one is working fine. would you please let me know what is wrong with my code below:

$(document).ready(function () {
    var dataTable = $("#emp_list").DataTable({
        searching:  true,
        processing: true,
        serverSide: true,
        paging: true,
        order: [],
        ajax: {
        url: "fetch.php",
        type: "POST",
        "data":
        //{selectdep: function() { return $('#selectdep').val()}},
        function ( d ) {
        d.check1 = check1;
        d.check2 = check2;
        d.check3 = check3;},                                                                                                                                                                              },
        });
$('#selectdep').on('change', function() { dataTable.ajax.reload();})
});

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited July 2022 Answer ✓

    Maybe you need something like this:

            ajax: {
                url: "fetch.php",
                type: "POST",
                "data": function(d) {
                    d.check1 = check1;
                    d.check2 = check2;
                    d.check3 = check3;
                    d.selectdep = $('#selectdep').val();
                },
            },
    
    

    Kevin

  • mahmoodrmmahmoodrm Posts: 4Questions: 2Answers: 0

    Thank you so much Kevin @kthorngren ! it's now working fine :smile:

Sign In or Register to comment.