使用spring springMVc 在ajax返回值时候出现了404 错误
Controller 代码
Controller 代码
@RequestMapping(value = "/login") public Object login(Model model, HttpSession session) { Map<String, String> map = new HashMap<String, String>(); ************************************* XXXXX登录验证 if(Tools.isEmpty(errInfo)){ errInfo =CONST.PD_SUCCESS; //验证成功 } -->>最后的map map.put("result", errInfo); // AppUtil.returnObject(new PageData(), map); return map;
AJAX
$.ajax({ type: "POST", url: "<%=path%>/user/login.do", data: {****}, dataType:"text", cache: false, success: function(data){ alert(data) if("success" == data.result){ saveCookie(); window.location.href="main/index"; }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } });
下面是报的错:
PS;已经跑到后台数据库 设置了 result的值
解决方案
20
controller应该不能返回object ,你这样试试:
public Map<String, String> getMap() {
Map<String, String> map = new HashMap<String, String>();
map.put(“key1”, “value-1”);
map.put(“key2”, “value-2”);
return map;
}
public Map<String, String> getMap() {
Map<String, String> map = new HashMap<String, String>();
map.put(“key1”, “value-1”);
map.put(“key2”, “value-2”);
return map;
}