嗨,我在Spring MVC中使用jQuery从数据库中获取book_id,但每次都收到错误提示
我已经使用jQuery ajax()方法并正确定义了所有参数,例如url,并且在Controller中我已经使用了所有正确的注释,但是未能获得输出。
$(document).ready(function () {
$("#bookId").keypress(function () {
var bookid = $(this).val();
alert($(this).val());
$.ajax({
url: "getBookQuantity.htm",
data: {
bookid : bookid
},
dataType: "json",
success: function (json) {
if (json !== null) {
alert(json);
}
},
error: function (e) {
alert("Some error occured while getting book id list");
}
});
});
});
控制器代码:
@RequestMapping(value = "/getBookQuantity.htm")
@ResponseBody
public String getBookQuantity(@RequestParam(value = "bookid", defaultValue = "0") int bookid) {
System.out.println("bookid======="+bookid);
int quantity = this.bookService.checkBookQuantity(bookid);
String json = null;
Gson gson = new Gson();
json = gson.toJson(quantity);
return json;
}
每次都会收到错误警报