SpringMvc ajax 404 问题

J2EE 码拜 8年前 (2016-03-14) 1638次浏览
使用spring springMVc  在ajax返回值时候出现了404 错误
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);
						}
				});

下面是报的错:
SpringMvc ajax 404 问题
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;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明SpringMvc ajax 404 问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)