Hello I want to be able to add additional data to my data being submitted on Ajax:
<script type="text/javascript">
$(document).ready(function() {
//http://www.datatables.net
$('#dataTable').dataTable({
"sPaginationType": "full_numbers",
"bJQueryUI": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Project/GetDataTables2",
"aoColumns": [
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true }
],
"fnServerData": function(url, data, callback) {
$.ajax({
"url": url,
"data": data, //I want to add additional data from here like the QueryString DPID
"success": callback,
"contentType": "application/x-www-form-urlencoded; charset=utf-8",
"dataType": "json",
"type": "POST",
"cache": false,
"error": function() {
alert("DataTables warning: JSON data from server failed to load or be parsed. " +
"This is most likely to be caused by a JSON formatting error.");
}
});
}
});
});
</script>
I tried doing:
data: data + "&moredata=" + morevalue
However I get a script error and it won’t send it to my URL… Please help!
Edit 1:
I am now passing it like this DPID comes across fine but dt does not:
<script type="text/javascript">
$(document).ready(function() {
//http://www.datatables.net
$('#dataTable').dataTable({
"sPaginationType": "full_numbers",
"bJQueryUI": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Project/GetDataTables2",
"aoColumns": [
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true }
],
"fnServerData": function(url, data, callback) {
$.ajax({
"url": url,
"data": { DPID: "1", dt: data }, //I want to add additional data from here like the QueryString DPID
"success": callback,
"contentType": "application/x-www-form-urlencoded; charset=utf-8",
"dataType": "json",
"type": "POST",
"cache": false,
"error": function() {
alert("DataTables warning: JSON data from server failed to load or be parsed. " +
"This is most likely to be caused by a JSON formatting error.");
}
});
}
});
});
</script>
if you want to add some additional data to the ajax request, use this: