Results 1 to 3 of 3

Thread: Failure Function is getting callback even after getting response from server

  1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    38
    Answers
    1

    Default Answered: Failure Function is getting callback even after getting response from server

    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.

  2. 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 :

    Code:
    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)?

  3. #2
    Sencha User carol.ext's Avatar
    Join Date
    Jun 2007
    Location
    Littleton, Colorado, USA
    Posts
    707
    Answers
    25

    Default

    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 :

    Code:
    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)?

  4. #3
    Sencha User
    Join Date
    May 2012
    Posts
    38
    Answers
    1

    Default

    great !!! Thanks its working fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •