【发布时间】:2018-08-17 01:02:35
【问题描述】:
我使用弹簧靴 2。 我做了一个 ajax 调用来保存表单。
$("#factoriesForm").submit(function (e) {
e.preventDefault();
debugger;
var factoriesId = $('#factoriesForm input[name="id"]').val();
var form = transForm.serialize('#factoriesForm');
form = JSON.stringify(form);
$.ajax({
type: "post",
url: "/template/edit/factories/" + factoriesId,
data: form,
contentType: "application/json",
dataType: "json",
success: function (data) {
$('#factoriesForm input[name="id"]').val(data.id);
new PNotify({
title: /*[[#{success.title}]]*/ ,
text: /*[[#{success.msg}]]*/ ,
type: 'error',
styling: 'bootstrap3',
delay: 4000
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
new PNotify({
title: /*[[#{error.title}]]*/ ,
text: /*[[#{error.msg}]]*/ ,
type: 'success',
styling: 'bootstrap3',
delay: 4000
});
}
});
});
春天我的控制者会做
@PostMapping("template/edit/factories/{id}")
@ResponseBody
public ResponseEntity<FactoriesDto> edit(Model model, @RequestBody FactoriesDto dto, @PathVariable("id") Integer id) {
return new ResponseEntity<>(factoriesFacace.save(dto), HttpStatus.OK);
}
保存已正确完成,但是当我在 js 中调试时,错误部分中的代码而不是成功。
JSON 输入意外结束”堆栈:“SyntaxError: Unexpected end of JSON 输入↵ at parse ()↵ at Ut (http://localhost:8080/webjars/jquery/3.3.1/dist/jquery.min.js:2:73768)↵ 在 k (http://localhost:8080/webjars/jquery/3.3.1/dist/jquery.min.js:2:77335)↵ 在 XMLHttpRequest。 (http://localhost:8080/webjars/jquery/3.3.1/dist/jquery.min.js:2:79907)"
状态码是 200。
【问题讨论】: