1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    103
    Vote Rating
    6
    abierbaum is on a distinguished road

      0  

    Default Ajax request returns success when no server and when cross-site blocked

    Ajax request returns success when no server and when cross-site blocked


    I am porting a ST1 application and have run into a surprising change in ST2. When I issue an Ext.Ajax.request to a URL and it returns a status of 0, ST2 now considers that to be a success. (ST1 considered it a failure).

    This is problematic for my application because status 0 is returned on both Mobile Safari and in Chrome when:

    1) The server at the other end does not exist and/or the server is not up and running
    2) The request is prevented because of cross-site scripting

    I need to detect both of these cases but I can't seem to find a good way of doing it right now.

    I wrote a test application you can see here on github: http://goo.gl/NrT7L

    The application attempts to request from several different URLs and presents the results.

    Results for chrome are:

    Log:
    Touch version: 2.0.0
    OS: Linux
    Browser: Chrome 17.0.963.79
    URL: ../../resources/css/app.css expecting: should pass
    success
    status: 200
    URL: http://localhost/blah expecting: server not responding
    success
    status: 0
    URL: /not_there expecting: file not found
    failure
    status: 404
    URL: http://servernotthere.com expecting: server does not exist
    success
    status: 0
    URL: http://www.google.com expecting: Cross site failure
    success
    status: 0
    URL: http://www.google.com/not_there expecting: cross site with bad url
    success
    status: 0
    Results on mobile safari running iOS 5.0.1 are the same.

    It seems to me that status code 0 should actually be treated as a failure. Is there some reason this change was made for ST2?

  2. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    try to listen on the requestexception see docs

    http://docs.sencha.com/touch/2-0/#!/...questexception

  3. #3
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    103
    Vote Rating
    6
    abierbaum is on a distinguished road

      0  

    Default


    I had thought of that, but it looks like exceptions only happen if the request is a failure. Since it is considered a success the event doesn't get fired.

  4. #4
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    Code:
    Fires if an error HTTP status was returned from the server. See HTTP Status Code Definitions for details of HTTP status codes.
    if you get an 404 error the event should be fired

    just try

    HTML Code:
    Ext.Ajax.request({            
      listeners: {                       
        requestexception: function() {               
         log_msg('requestexception');            
       }            
    },
    ..

  5. #5
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    103
    Vote Rating
    6
    abierbaum is on a distinguished road

      0  

    Default


    I updated the example to show requestexception and requestcomplete events. It shows the same problem. When the status code is 0, the requestcomplete is called just as the success handler is called.

    To further clarify the issue I am seeing, I consider the requests that come back with status of 200 and status of 404 to be behaving correctly. So as @mrsunshine points out, the 404 request will call the correct callbacks.

    My concern is only with the ones where the HTTP status returned is 0. Previously a 0 status was treated as an error (call failure handler and requestexception) but now it is treated as a success (call success handler and requestcomplete). That makes it impossible for me to detect the case of missing servers, connection failures, and cross-site request errors.

  6. #6
    Sencha User
    Join Date
    Dec 2010
    Posts
    68
    Vote Rating
    -1
    jairok is an unknown quantity at this point

      0  

    Default


    I've exactly the same problem...
    So anybody got a solution ?

  7. #7
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    103
    Vote Rating
    6
    abierbaum is on a distinguished road

      0  

    Default


    It is a bit heavy handed, but this is what I am doing for now. It will go back to ST1 behavior of treating status 0 as a failure.

    /*
    * Override the parseStatus method to consider 0 as a failure.
    */
    Ext.define('Ext.overrides.Connection', {
    override: 'Ext.data.Connection',


    parseStatus: function(status) {
    var ret_val = this.callParent(arguments);


    if(0 === status) {
    ret_val.success = false;
    //console.log('set to fail');
    }


    return ret_val;
    }
    });

Thread Participants: 2

Tags for this Thread