I am new to AngularJS and DataTables. I am working on a project using an AngularJS front-end and a Rails back-end.
I am trying to use DataTables in my project using AJAX POST method but DataTable AJAX POST method is sending data params constants.
When I am using a normal AJAX POST request it works fine. I don't know why DataTables POST AJAX is not working.
Please help me to solve this problem.
Using AJAX call in AngularJS
$.ajax({
data: JSON.stringify({
"key1": "value1",
"key2": "value2"
}),
headers: "application/json; charset=utf-8",
success: function(data){
console.log(data);
},
error: function(){
console.log("error");
},
type: "POST",
url: "http://localhost:3000/api"
});
This code AJAX POST.
It gives the correct success response.
DataTables POST request
$scope.studentList = {
bFilter: false,
paging: false,
bRetrieve : true,
ajax: {
data: JSON.stringify({
"key1": "value1",
"key2": "value2"
}),
headers: "application/json; charset=utf-8",
success: function(data){
console.log(data);
},
error: function(){
console.log("error");
},
type: "POST",
url: "http://localhost:3000/api"
processData: false,
},
columns: [
{}]
};
It throws the following error on the server-side. Is there any mistake in my code?
Error occurred while parsing request parameters.
Contents:
0=%7B&1=%22&2=s&3=t&4=a&5=n&6=d&7=a&8=r&9=d&10=&11=i&12=d&13=%22&14=%3A&15=4&16=0&17=%2C&18=%22&19=s&20=e&21=c&22=t&23=i&24=o&25=n&26=&27=i&28=d&29=%22&30=%3A&31=8&32=%2C&33=%22&34=y&35=e&36=a&37=r&38=%22&39=%3A&40=2&41=0&42=1&43=6&44=%2C&45=%22&46=m&47=o&48=n&49=t&50=h&51=%22&52=%3A&53=2&54=%2C&55=%22&56=d&57=a&58=t&59=e&60=%22&61=%3A&62=1&63=8&64=%7D
Even though I am using processData: false option it still throws the following error on the server-side.
Error occurred while parsing request parameters.
Contents:
[object Object]
Please help me to solve this issue.
I am new to AngularJS and DataTables. I am working on a project using an AngularJS front-end and a Rails back-end.
I am trying to use DataTables in my project using AJAX POST method but DataTable AJAX POST method is sending data params constants.
When I am using a normal AJAX POST request it works fine. I don't know why DataTables POST AJAX is not working.
Please help me to solve this problem.
Using AJAX call in AngularJS
$.ajax({
data: JSON.stringify({
"key1": "value1",
"key2": "value2"
}),
headers: "application/json; charset=utf-8",
success: function(data){
console.log(data);
},
error: function(){
console.log("error");
},
type: "POST",
url: "http://localhost:3000/api"
});
This code AJAX POST.
It gives the correct success response.
DataTables POST request
$scope.studentList = {
bFilter: false,
paging: false,
bRetrieve : true,
ajax: {
data: JSON.stringify({
"key1": "value1",
"key2": "value2"
}),
headers: "application/json; charset=utf-8",
success: function(data){
console.log(data);
},
error: function(){
console.log("error");
},
type: "POST",
url: "http://localhost:3000/api"
processData: false,
},
columns: [
{}]
};
It throws the following error on the server-side. Is there any mistake in my code?
Error occurred while parsing request parameters.
Contents:
0=%7B&1=%22&2=s&3=t&4=a&5=n&6=d&7=a&8=r&9=d&10=&11=i&12=d&13=%22&14=%3A&15=4&16=0&17=%2C&18=%22&19=s&20=e&21=c&22=t&23=i&24=o&25=n&26=&27=i&28=d&29=%22&30=%3A&31=8&32=%2C&33=%22&34=y&35=e&36=a&37=r&38=%22&39=%3A&40=2&41=0&42=1&43=6&44=%2C&45=%22&46=m&47=o&48=n&49=t&50=h&51=%22&52=%3A&53=2&54=%2C&55=%22&56=d&57=a&58=t&59=e&60=%22&61=%3A&62=1&63=8&64=%7D
Even though I am using processData: false option it still throws the following error on the server-side.
Error occurred while parsing request parameters.
Contents:
[object Object]
Please help me to solve this issue.
Share Improve this question edited Oct 31, 2016 at 19:17 Carlos Ramirez III 7,43430 silver badges35 bronze badges asked Jan 20, 2016 at 13:48 Sasikala JSasikala J 5265 silver badges14 bronze badges 1- Check out this: datatables/forums/discussion/26282/… – ge333 Commented Jan 14, 2022 at 17:58
4 Answers
Reset to default 1In dataTables you can not pass a string in data, you need a function:
var dataObject = {
"key1": "value1",
"key2": "value2"
};
var table = $('#exampleTable').DataTable({
ajax: {
"url": "urlExample.",
"type": "POST",
"data": function(d) {
$.extend(d, dataObject);
return JSON.stringify(d);
},
"dateType": "json",
"contentType": "application/json; charset=utf-8"
}
});
Try removing JSON.stringify. data table or ajax internally handles JSON parsing/stringification.
Use this instead :
$('#example').dataTable({
"ajax": {
"url": "data.json",
"contentType": "application/json",
"type": "POST",
"data": function (d) {
return JSON.stringify(d);
}
}
});
var table = $('#datatable').DataTable({
// "processing": true,
"serverSide": true,
"ajax": 'controller/documents/getDocExpAjax',
"type": 'POST',
"data": function (d) {
return JSON.stringify(d);
},
"dateType": "json",
"contentType": "application/json; charset=utf-8"
});