【发布时间】:2019-06-08 02:52:11
【问题描述】:
我正在使用带有 GET 方法的 ajax,我正在等待接收 JSON,但有时响应为 null 并得到错误:
SyntaxError: JSON 输入意外结束
ajax:
$(document).ready(function() {
$("#form_data").submit(function(e) {
e.preventDefault()
var expediente = $('#expediente').val();
$.ajax({
url : 'buscarPaciente' + '?expediente=' + expediente,
dataType : "json",
type : "GET",
contentType : 'application/json',
mimeType : 'application/json',
success : function(data) {
console.log(data.nombre);
},
error : function(xhr, status, error) {
console.log(error)
}
});
})
});
在控制器中:
@RequestMapping(value="/buscarPaciente", method = RequestMethod.GET)
public @ResponseBody MntPaciente
buscarPaciente(@RequestParam("expediente") String expediente) {
MntPaciente mntPaciente = servicePx.findByexpediente(expediente);
if (mntPaciente!= null) {
return mntPaciente;
}
return null; // Should I return an empty json? how?
}
【问题讨论】:
标签: ajax spring-mvc