我有一个 jquery 函数,我有 2 种类型的字符串和数组,如果我只传递字符串类型,它会命中控制器并且工作正常,但是如果我将数组连同它一起传递,我会收到网络错误 400 错误请求。我该怎么做。代码如下
function saveFocusGrp() {
var focusName = window.prompt('Please enter the focus group name:');
var enteredFocusList = [];
enteredFocusList = focuslist; // here focuslist is declared globally and is assigned the value in other function which I'm getting it in this function it will be in the form abc,def,xyz
alert("focus Name====>" + focusName);
alert("focus List====> " + enteredFocusList); // I get the values here in alert too
$.ajax({
url : '/DataWeb/saveFocusData',
type : 'get',
dataType : 'json',
data : { focusGroupName : focusName, focusList : enteredFocusList },
success : function(map) {
console.log(map);
var $out = $('#focusGroupName');
$out.html(map.successMsg);
}
});
}
我在 firebug 中遇到的错误是:NetworkError: 400 Bad Request
家庭控制器代码:
@RequestMapping(value = "/saveFocusData", method = RequestMethod.GET)
public void saveFocusData(HttpServletRequest req, HttpServletResponse res,
@RequestParam("focusGroupName") String focusGroupName,
@RequestParam("focusList") List focusList) throws IOException {
System.out.println("Inside home controller============");
Gson json = new Gson();
res.setContentType("application/json");
HashMap<String, String> map = new HashMap<String, String>();
String successMsg="";
map.put("successMsg", successMsg);
res.getWriter().print(json.toJson(map));
}