我今天写了一个ajax操作:
判断用户的状态决定其拥有什么权限,但每次执行第一个后
改变条件,再执行,还是返回第一次的结果,这是为什么,有没有那位高手能告诉我是什么原因?
js代码:
function checkLogin(){
var temp;
var map = {};
$.ajax({
url : "userLand.do?method=checkLogin",
async : false,
data : map,
success : function(msg){
var ret = $.trim(msg);
if(ret == "nologin"){
if(confirm("您需要登录后才能使用此功能,现在就登录吗?")){
window.location.href = "app/main/userLogin.jsp";
}
temp = false;
msg="";
}
if(ret == "shenhe"){
alert("您现在处于未审核状态,只有浏览权限");
temp = true;
msg="";
}
if(ret == "stop"){
alert("您现在处于暂停状态,只有浏览权限");
temp = true;
msg="";
}
if(ret == "ok"){
temp = true;
msg="";
}
}
});
return temp;
}
Action:
public ActionForward checkLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
//获取当前登录用户信息(0:未审核,2:暂停,1:正常)
LoginInfo logininfo = SysUtil.getCurrUserSession(request);
String msg = "";
if(logininfo == null){
msg = "nologin";
}else if(logininfo.getUserStatus() == "0"){
msg = "shenhe";
}else if(logininfo.getUserStatus() == "1"){
msg = "ok";
}
PrintWriter out = response.getWriter();
out.print(msg);
out.close();
return null;
}