当我提交表单时,我有一个包含两个文本框的用户名和密码的表单,我的小服务程序是
成功调用并正确发送响应。但在提交方法失败正在被调用。失败函数即使在获得服务器响应后也得到回调
这是我的代码。
form.submit({
success: function(form, action) {
console.log(action);
alert("Success");
},
failure: function(form, action) {
console.log(action);
alert("fail");
}
});
我的Servlet代码。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
JSONObject obj=new JSONObject();
try {
obj.put("sucess",true);
out.print(obj.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是,如果我用Ext.Ajax成功函数取代form.submit成功调用。
Ext.Ajax.request({
url:"login",
success: function(result, request) {
alert("success");
},
failure:function(response){
alert("failure");
console.log(response);
}
});
为什么form.submit无法正常工作?
注意:我没有在服务器端进行任何身份验证,我的意图是检查我是否能够从服务器获取json响应,对于Ext.Ajax.Request,我不发送参数。