PDA

View Full Version : Failure Function is getting callback even after getting response from server



tsuryap
23 Nov 2014, 10:24 AM
I have a form which contains two textfields username and password when I submit the form my servlet is
getting called successfully and sending reponse properly. But in submit method failure is getting called.

Here is my code.

form.submit({
success: function(form, action) {
console.log(action);
alert("Success");
},
failure: function(form, action) {
console.log(action);
alert("fail");
}

});
My Servlet code.





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();
}

}
But if i have replaced form.submit with Ext.Ajax success function is getting called successfully.



Ext.Ajax.request({
url:"login",
success: function(result, request) {
alert("success");
},
failure:function(response){
alert("failure");
console.log(response);
}
});


Why form.submit not working properly ??


Note:I am not doing any authentication at server side my intention is to check whether I am able to get json response from server,For Ext.Ajax.Request I am not sending params.

carol.ext
24 Nov 2014, 12:10 PM
As I recall, the form submit calls success/failure handler based on success: true/false. Ajax.request uses the request's response code and not success: true/false to determine which handler to call.

Your JSONObject is setting success spelled wrong :


JSONObject obj=new JSONObject();
try {
obj.put("sucess",true);
out.print(obj.toString());



If you indicate that was just a typo in the post, please provide more information about your form submit. Is it a regular form submit or Ajax? What does the response look like in the console (Firebug or Chrome)?

tsuryap
24 Nov 2014, 6:56 PM
great !!! Thanks its working fine