响应性无价值返回错误
我有一个带有百里叶应用程序的春季启动
启动ajax调用该代码,
$.ajax({
type: "post",
url: "/subscriptionsavetestament",
async: false,
data: testamentJson,
contentType: 'application/json',
dataType: 'json',
beforeSend: function(request) {
request.setRequestHeader(header, token);
},
success: function(data){
....
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("error: " + textStatus);
}
});
该控制器被称为该代码,
public ResponseEntity subscriptionsavetestament(@RequestBody TestamentWizard testamentDocument){
...
return new ResponseEntity(HttpStatus.OK);
}
但我在javascript侧侧错误解析上遇到了一个错误...
如果我修改了我的控制器以
public ResponseEntity subscriptionsavetestament(@RequestBody TestamentWizard testamentDocument){
...
return new ResponseEntity(true, HttpStatus.OK);
}
适合使用,但是我不这样做了解为什么
服务器仅返回状态,没有身体中的任何内容,为什么必须如何进行AJAX调用?
编辑:
删除数据类型解决问题
I have a spring boot with thymeleaf application
An ajax call is made wit this code
$.ajax({
type: "post",
url: "/subscriptionsavetestament",
async: false,
data: testamentJson,
contentType: 'application/json',
dataType: 'json',
beforeSend: function(request) {
request.setRequestHeader(header, token);
},
success: function(data){
....
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("error: " + textStatus);
}
});
This controller is called
public ResponseEntity subscriptionsavetestament(@RequestBody TestamentWizard testamentDocument){
...
return new ResponseEntity(HttpStatus.OK);
}
But I get alway an error on the javascript side error parsing...
If I modify my controller for
public ResponseEntity subscriptionsavetestament(@RequestBody TestamentWizard testamentDocument){
...
return new ResponseEntity(true, HttpStatus.OK);
}
that work fine, but I don't understand why
how the ajax call must be done if the server return only the status, nothing in the body?
Edit:
Removing dataType fix the issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码返回使用200个状态代码的空体,
如果您不想发送200,那么更好的方法将直接使用
nocontent
这将提供HTTP 204You can return empty body with 200 status code using following code
If you do not want to send 200 then a better way would be directly use
noContent
this will give HTTP 204