我的Ajax调用看起来像这样
function Submit() {
var objectData =
{
email: $("#email").val(),
firstName: $("#firstName").val(),
lastName: $("#lastName").val(),
loginMode: $("#loginMode").val(),
primaryMobile: $("#primaryMobile").val()
};
var objectDataString = JSON.stringify(objectData);
console.log(objectDataString);
$.ajax({
type: "POST",
url: "http://localhost:8080/feasthunt/customer/saveCustomerDetails",
contentType: "application/json; charset=utf-8",
data: objectDataString,
dataType: "json",
success: function (data) {
alert('Success');
$objectDataString.append('<li>email: '+data.email+', firstName: '+data.firstName+', lastName: '+data.lastName+', loginMode: '+data.loginMode+', primaryMobile: '+data.primaryMobile+ '</li>');
},
error: function () {
alert('Error');
}
});
}
我在控制台中收到的错误如下:
POST
XHR
http://localhost:8080/feasthunt/customer/saveCustomerDetails [HTTP/1.1 400 Bad Request 123ms]
为什么会这样?
答案 0 :(得分:0)
确保请求和响应的contentType
匹配。