當我提交表單時,我有一個包含兩個文本框的用戶名和密碼的表單,我的小服務程序是
成功調用並正確發送響應。但在提交方法失敗正在被調用。失敗函數即使在獲得服務器響應後也得到回調
這是我的代碼。
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,我不發送參數。
是得到相同的格式,因爲我說它工作正常ext.ajax請求 – 2014-11-24 14:49:41
對不起 - 意味着做一個評論,而不是一個答案 - 你不會碰巧具有配置與standardSubmit的形式:真正配置?否則,可能會解析並在發回的操作對象中找到響應 - 更新我的答案並提供有關如何執行此操作的詳細信息。 – 2014-11-24 19:20:40