数据表后请求参数不起作用
Data table post request params not working
我是AngularJS和DataTables的新手。我正在开发一个使用AngularJS前端和Rails后端的项目。
我正在尝试使用AJAX POST方法在我的项目中使用DataTables,但是DataTable AJAX POST方法正在发送数据参数常量。
当我使用普通的 AJAX POST 请求时,它工作正常。我不知道为什么DataTables POST AJAX不起作用。
请帮我解决这个问题。
在 AngularJS 中使用 AJAX 调用
$.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"
});
此代码 AJAX 发布。
它给出正确的成功响应。
数据表 POST 请求
$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: [
{}]
};
它在服务器端引发以下错误。我的代码中是否有任何错误?
解析请求参数时出错。
内容:
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
即使我正在使用 processData: false 选项,它仍然会在服务器端抛出以下错误。
解析请求参数时出错。
内容:
[对象对象]
请帮我解决这个问题。
在 dataTables 中,你不能在数据中传递字符串,你需要一个函数:
var dataObject = {
"key1": "value1",
"key2": "value2"
};
var table = $('#exampleTable').DataTable({
ajax: {
"url": "urlExample.com",
"type": "POST",
"data": function(d) {
$.extend(d, dataObject);
return JSON.stringify(d);
},
"dateType": "json",
"contentType": "application/json; charset=utf-8"
}
});
尝试删除 JSON.stringify。 数据表或 AJAX 在内部处理 JSON 解析/字符串化。
改用这个:
$('#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"
});
相关文章:
- setTimeout刷新,毫秒参数不起作用
- 角度限制过滤器's的第二参数“s”;“开始”;在Angular 1.3中似乎不起作用
- 参数使用AJAX的PHP POST不起作用
- UI 路由器参数 URL 不起作用,只是重定向到 /
- JavaScript参数对象不起作用
- 筛选器's的第二个参数不起作用
- 使用输入名称参数在jQuery中取整不起作用
- 在Angular Directive中传递函数作为参数不会;不起作用
- 如果我移除animateTo参数,.remove()回调函数将不起作用
- .eq()参数在循环中不起作用
- 谷歌地图API v3-缩放参数don'不起作用
- UIWebView调用带有参数的JS获胜'不起作用
- JavaScript - 在函数内连接 2 个参数不起作用
- 参数在使用 Google Apps 脚本的 Google 云打印中不起作用
- 参数在 $() - jQuery 之外不起作用
- 为什么传入的参数在一个地方有效,而在另一个地方不起作用
- jQuery 参数不起作用
- 函数在将参数传递给 addEventListener 时不起作用
- angularjs路由不起作用参数'CatCtrl'不是函数,未定义
- Javascript ADO 记录集打开方法不起作用.参数化查询