[英]showing 400 (Bad Request) in ajax
I am using cordova and while doing json i am getting an error "Failed to load resource: the server responded with a status of 400 (Bad Request) ".我正在使用cordova,在执行json时出现错误“无法加载资源:服务器响应状态为400(错误请求) ”。
But the same code when I run it on postman is getting the right answer.Please help me to solve this problem.但是当我在邮递员上运行相同的代码时得到了正确的答案。请帮我解决这个问题。 The code is:
代码是:
$.ajax({
url: url,
type: "POST",
async: false,
ContentType: "application/json; charset=utf-8",
data: jData,
dataType: "json",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
},
});
And a screenshot of the right answer on the postman is also given for your reference并附上邮递员上正确答案的截图,供大家参考
you need to stringify the JSON data was sending您需要对正在发送的 JSON 数据进行字符串化
$.ajax({
type: 'POST',
url: url,
async: false,
data: JSON.stringify(jData),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
Try removing the open and closing brackets around your jData尝试删除 jData 周围的左括号和右括号
var jData = {}; var jData = {};
Not不是
var jData = [{}]; var jData = [{}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.