Javascript 无法在Jquery中发送数组-给予NetworkError 400错误请求
我有一个jquery函数,我有两种类型string和array,如果我只传递string类型,它会命中控制器并正常工作,但是如果我同时传递array,我会得到网络错误400错误请求。我该怎么做呢。代码如下Javascript 无法在Jquery中发送数组-给予NetworkError 400错误请求,javascript,jquery,Javascript,Jquery,我有一个jquery函数,我有两种类型string和array,如果我只传递string类型,它会命中控制器并正常工作,但是如果我同时传递array,我会得到网络错误400错误请求。我该怎么做呢。代码如下 function saveFocusGrp() { var focusName = window.prompt('Please enter the focus group name:'); var enteredFocusList = []; enteredFocus
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错误请求
家庭控制器代码:
@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));
}
@RequestMapping(value=“/saveFocusData”,method=RequestMethod.GET)
public void saveFocusData(HttpServletRequest-req、HttpServletResponse-res、,
@RequestParam(“focusGroupName”)字符串focusGroupName,
@RequestParam(“focusList”)列表(focusList)引发IOException{
System.out.println(“内部主控制器=================”;
Gson json=new Gson();
res.setContentType(“应用程序/json”);
HashMap=newHashMap();
字符串successsg=“”;
地图放置(“successsg”,successsg);
res.getWriter().print(json.toJson(map));
}
我假设问题在于控制器如何解释焦点列表
参数。请给我们你的控制器部分。也许是因为你有你的类型。你有没有试着用post?是的。。我也试过用post。。它给了我同样的错误尝试在发送时转义数据,在接收时转义数据。另外:使用json函数对数据进行字符串化和非序列化。