1
回答
SpringMVC中controller如何接收ajax请求的返回值并完成跳转页面
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   
@RequestMapping("modifyPassword")
	@ResponseBody
	public Map<String, Object> modifyPassword(HttpSession session, HttpServletRequest request){
		Map<String, Object> map = new HashMap<>();
		Account localAccount = (Account)session.getAttribute("account");
		String password = request.getParameter("password");
		localAccount.setPassword(password);
		if(accountService.saveUser(localAccount)){
			session.invalidate();
			map.put("data", "success");
		}
		return map;
	}
$(".modify-password-btn").click(function(){
		var password = $("#user_psd").val();
		
		jQuery.ajax({
			dataType: "json",
			cache:false,
			url: "modifyPassword",
			data:{
				password:password
			},
			success: function(data){
				if(data.data){
					console.log(data.data);
					zeroModal.success({
						content:"操作成功,点击返回登入界面",
						ok:true,
						okFn:function(){
							location.href = "login.jsp";
						}
					});
					return false;
				}
			},
			error:function(data){
				alert(data.data);
			}
			
		});
	});

我这样写可以吗?

举报
SeizeMissing
发帖于1年前 1回/2K+阅
顶部