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
izumov
Posts: 178Questions: 14Answers: 0
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
This discussion has been closed.
Answers
Hi @izumov ,
Use
ajax.data
,Cheers,
Colin
Hi izumov!
Just to add to what colin has said.
I can spot 3 things that are going on here...
On line 20 you need to wrap your selector in quotation marks, this is evaluating your parameter to undefined.
Also on line 20, Value is not a valid method and should be replaced by val. Line 20 should read:
Hope this helps!
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?
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
Thanks.I've made the code work.