无法在Jquery中发送数组 - 给出NetworkError 400错误请求

时间:2012-11-09 09:07:28

标签: javascript jquery

我有一个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));    
}

0 个答案:

没有答案