how to pass 2 or more custom parameters to the server in an Ajax request

how to pass 2 or more custom parameters to the server in an Ajax request

izumovizumov Posts: 178Questions: 14Answers: 0
edited May 2019 in Free community support

My code

var id;
$(document).ready(function()
 
    {   
id=16;  
    $('#orders').DataTable( {  
         "order": [[ 0, "desc" ]],
         select: true,     
         scrollY: true,   
         scrollX:true,    
         "sRowSelect": "single",   
        "processing": true,   
        "bPaginate": true,   
        "bSort": true,  
        "serverSide": true,
        "autoWidth":true,
        "ajax": {
        url:"server_processingorders011.php",  
        data:function(d){d.kod=id, 
        d.startdate=$(#StartDat).Value;}  
        }  
    

    } );  
    $('#clients tbody').on('dblclick', 'tr', function () { 
        var table =$('#clients').DataTable();  
        var data = table.row( this ).data();  
        document.location.href="http://localhost/order.php?id="+data[0];  

    } );  
     });  

In the built-in debugger, I see that only the kod parameter is sent in the request.WHAT I'm doing wrong. how to change the code to be able to send 2 or more parameters.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @izumov ,

    Use ajax.data,

    Cheers,

    Colin

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi izumov!

    Just to add to what colin has said.

    I can spot 3 things that are going on here...

    1. On line 19 you are using a comma where you should be using a semicolon. Line 19 should read :
    data:function(d){d.kod=id;
    
    1. On line 20 you need to wrap your selector in quotation marks, this is evaluating your parameter to undefined.

    2. Also on line 20, Value is not a valid method and should be replaced by val. Line 20 should read:

    d.startdate=$("#StartDat").val();}
    

    Hope this helps!

  • izumovizumov Posts: 178Questions: 14Answers: 0

    section ajax I changed the following way.
    "ajax": {
    url:"server_processingorders011.php",
    data:function(d){d.kod=id;
    d.startdate=document.getElementById('StartDate').Value;
    d.enddate=document.getElementById('EndDate').Value;}
    }

    and two parameters kod and StartDate were passed. EndDate is not transmitted. How do I achieve the transfer of all three parameters? Is there any limit to the number of user parameters?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @izumov ,

    That should work - see this test case here that's doing just that (you can confirm by checking the network of the developer's tools). Can you link to your page or modify the test case to demonstrate the problem, please.

    Cheers,

    Colin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    Thanks.I've made the code work.

This discussion has been closed.