【发布时间】:2020-08-09 03:43:42
【问题描述】:
我想从控制器收集数据到 ajax 并在单击按钮编辑时将其显示给模态 JSP。但我收到了一个错误 500。
simulation.jsp
<button class="btn btn-primary btn-edit" data-id="${simulasis.id}">Update</button>
Admin.js
$(document).ready(function () {
$('.table .btn-edit').on('click', function (event) {
event.preventDefault();
var id = {'id': $(this).attr('data-id')};
$.ajax({
url: '/backoffice/edit',
data: id,
contentType: "application/json",
dataType: "json",
type: 'GET',
success: function (response) {
$('#idEdit').val(response.id);
console.log("success");
},
error: function (jqxhr) {
console.log(this.url);
console.log(response);
}
});
console.log(id);
$('#edit-modal-lg').modal();
});
});
BackofficeController.java
@RequestMapping(value = "/edit", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Simulasi getById(@RequestParam("id") int id){
return simulasiService.getSimulasi(id);
}
我遇到了这样的错误,
【问题讨论】:
-
做一些测试以直接在浏览器中获取您请求的 URL。也许它会更有表现力并且很容易获得信息。如果是 500 代码的错误,那么它可能是很多事情,但我会通过逐步调试过程查看 url 参数、请求参数和它应该生成的代码。如果有的话,您会更快地找到错误所在的位置
标签: java ajax spring-mvc