ext请求checkNewPassword方法之后,将参数传给java代码,无论返回的是成功还是失败都不执行最后failure : function(resp, opts) 这段代码!
EXT代码
Ext.Ajax.request({
url : Global_Path + '/portal/person/user.do?method=checkNewPassword',
method :'post',
params : {
comfirmPassword : userPwdNew ,
comfirmrtUser : userID,
comfirmrtchangepwd : changepwd
},
success: function(resp, opts) {
/*var backStr = opts.result; alert(backStr) ;*/ Ext.Ajax.request({
url : Global_Path + '/logonpwd.do?method=userpasswordmodfy',
method : 'post',
params : {
userID : userID,
oldpassword : userPwdOld,
newpassword : userPwdNew
},
success : function(respp, optss) {
Ext.Msg.alert('提示', '新密码修改成功!', function() {
window.location.href = Global_Path + '/login.jsp';
});
},
failure : function(respp, optss) {
var backval = eval('(' + respp.responseText + ')');
var text = backval.text;
Ext.Msg.alert('提示', '密码修改失败!');
}
}); },
failure : function(resp, opts) {
var backStr = resp.responseText;
//var backStrww=Ext.util.JSON.decode(req.responseText)
/*alert(backStr) ;*/
Ext.Msg.alert('提示', '密码修改失败!!!');
window.location.href = Global_Path + '/login.jsp';
}
});
} ; });java代码 if (msg.equals("成功")) {
try {
response.getWriter().print("{success:true,info:{}}");
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//this.sendSuccessMsg(response, "修改成功", "0007");
return null;
} if(!msg.equals("成功")) {
try { // request.setAttribute("msg", msg);
response.getWriter().print("{success:false,error:{}}");
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//this.sendFailMsg(response, msg, "0001");
return null;
}
}
EXT代码
Ext.Ajax.request({
url : Global_Path + '/portal/person/user.do?method=checkNewPassword',
method :'post',
params : {
comfirmPassword : userPwdNew ,
comfirmrtUser : userID,
comfirmrtchangepwd : changepwd
},
success: function(resp, opts) {
/*var backStr = opts.result; alert(backStr) ;*/ Ext.Ajax.request({
url : Global_Path + '/logonpwd.do?method=userpasswordmodfy',
method : 'post',
params : {
userID : userID,
oldpassword : userPwdOld,
newpassword : userPwdNew
},
success : function(respp, optss) {
Ext.Msg.alert('提示', '新密码修改成功!', function() {
window.location.href = Global_Path + '/login.jsp';
});
},
failure : function(respp, optss) {
var backval = eval('(' + respp.responseText + ')');
var text = backval.text;
Ext.Msg.alert('提示', '密码修改失败!');
}
}); },
failure : function(resp, opts) {
var backStr = resp.responseText;
//var backStrww=Ext.util.JSON.decode(req.responseText)
/*alert(backStr) ;*/
Ext.Msg.alert('提示', '密码修改失败!!!');
window.location.href = Global_Path + '/login.jsp';
}
});
} ; });java代码 if (msg.equals("成功")) {
try {
response.getWriter().print("{success:true,info:{}}");
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//this.sendSuccessMsg(response, "修改成功", "0007");
return null;
} if(!msg.equals("成功")) {
try { // request.setAttribute("msg", msg);
response.getWriter().print("{success:false,error:{}}");
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//this.sendFailMsg(response, msg, "0001");
return null;
}
}
你可以设置返回值,举个例子。返回success为成功,返回failure为失败,那么在ajax请求成功的事件——即success事件中通过这个返回值来判断。当然,如果请求失败,即触发failure事件,那么肯定也是修改失败的。
能不能说的详细点呢? 我现在是这样如果后台判断不成功
response.getWriter().print("{success:false,errors:{}}");是这样返回的!
那么JS中就需要在success中判断result的值是否为true
success: function(result, request) {
var responseArray = Ext.util.JSON.decode(result.responseText);
result = responseArray.success;
...
}当然如果是采用表单提交,是不会出现你说的问题的,如果后台抛异常,它会执行failure里面的语句