我对这个错误有这些链接,但我的问题还没有解决。 Here,Here,我查了一些,但他们是基于json。所有Spring MVC Ajax 406不好的请求
首先我告诉你,同样的代码在我的另一个项目工作的事情是,我必须实现JSP和serlvets该项目,这一次在春季和休眠。
事情是请求来的方法。当它返回时。消息出现在控制台400错误请求中。
这是我的方法
@RequestMapping(value = "/populateBillItems")
public @ResponseBody List<String> populateItems(@RequestParam String catName) {
itemNames = productService.getItemNames(catName);
return itemNames;
}
的Javascript
function populateItems(obj){
var itemCategory = obj.value;
$.get('populateBillItems', {
catName : itemCategory
}, function(response) {
var select = $('#itemName');
select.find('option').remove();
$.each(response, function(index, value) {
$('<option>').val(value).text(value).appendTo(select);
});
});
}
你可以看到该值是从数据库中检索,但当响应返回时,这个错误来自控制台
GET http://localhost:8080/InventoryManagementSystemUsingSpring/populateBillItems?catName=Rice 406 (Not Acceptable)
这是第一个问题。
我有jQuery中的另一个功能,发送请求到控制器,并得到ID和一个文本框填充它。它也给出了同样的错误上面一个是给..
function populateBillId(obj){
var objValue=obj.value;
var table="";
if(objValue=='Borrower'){
table="BorrowerBill";
alert(table);
$("#customerName").prop("readonly", true);
}else if(objValue=='Customer'){
$("#customerName").prop("readonly",false);
table="CustomerBill";
}
$.get('populateBillId', {
tableName : table
}, function(response) {
var id=response;
$("#billId").val(id);
});
}
GET http://localhost:8080/InventoryManagementSystemUsingSpring/populateBillId?tableName=BorrowerBill
的问题几乎解决了。现在,我得到我已经作出了效应初探方法的值这样
@RequestMapping(value = "/populateBillItems")
public @ResponseBody String populateItems(@RequestParam String catName) {
itemNames = productService.getItemNames(catName);
String json=null;
json = new Gson().toJson(itemNames);
return json;
}
和modeified的JQuery这样
function populateItems(obj){
var itemCategory = obj.value;
$.get('populateBillItems', {
catName : itemCategory
}, function(response) {
var select = $('#itemName');
select.find('option').remove();
$.each(JSON.parse(response, function(index, value){
$('<option>').val(value).text(value).appendTo(select);
}));
});
}
但现在的问题是,我也越来越(双引号)“”中的选项
这些都是与itemNames选择框和文本字段标识
报价
400错误请求错误通常表示服务器在请求中收到的属性导致错误。我会检查你发送的内容以及服务器在做什么。你的JS代码不太可能成为问题(除了输入缺陷之外),我将开始调试'productService.getItemNames'调用。 –
该请求正在服务器上,它甚至对其执行操作。但是在方法返回响应之后,这个消息就来了。 –
您可以看到结果显示项目是从数据库中检索的。所以我认为它没有错误。 –