Extjs 解决表单提交总是执行failure回调函数

来源:互联网 发布:使用excel制作软件 编辑:程序博客网 时间:2024/05/21 20:49

Extjs 解决表单提交总是执行failure回调函数

标签: extjsactionfunctionstringserverjson
 787人阅读 评论(0) 收藏 举报
 分类:
 

Extjs提交表单

[javascript] view plain copy
  1. success:function(form,action){  
  2.                var data=Ext.JSON.decode(action.response.responseText);  
  3.                Ext.Msg.alert("www ok",data.id);  
  4.             },  
  5.             failure: function(form, action){  
  6.                 if (action.failureType === action.CONNECT_FAILURE) {  
  7.                     Ext.Msg.alert('Error',  
  8.                         'Status:'+action.response.status+': '+  
  9.                         action.response.statusText);  
  10.                 }  
  11.                 if (action.failureType === action.SERVER_INVALID){  
  12.                     // server responded with success = false  
  13.                     Ext.Msg.alert('Invalid', action.result.errormsg);  
  14.                 }  
  15.                 Ext.Msg.alert('Invalid',action.failureType);  
  16.             }  
java后台

[java] view plain copy
  1. public class loginAction extends HttpServlet {  
  2.     public void doGet(HttpServletRequest request, HttpServletResponse response)  
  3.     throws ServletException, IOException {  
  4.           
  5.         String username= request.getParameter("username");  
  6.         String password= request.getParameter("password");  
  7.           
  8.         if(username.equals("www")&&password.equals("123")){  
  9.             response.getWriter().write("{id:0001}");  
  10.             System.out.println(username+password);  
  11.         }  
  12.     }  
  13. }  

可是,找了好久,发现怎么都是执行的failure的回调函数  action.failureType为server,百思不得其解

后来发现 回调success或failure是根据返回来的参数的json串中的"success"的值来决定的

response.getWriter().write("{id:0001}");    

应该改为  response.getWriter().write("{success:true,id:0001}");

就可以解决问题

0 0