1. #1
    Ext JS Premium Member
    Join Date
    Jul 2011
    Posts
    22
    Vote Rating
    0
    mmaltby is on a distinguished road

      0  

    Default xmlhttprequest status equals 0 for local files

    xmlhttprequest status equals 0 for local files


    When running qunit we are using mock json files that are local. The ajax call returns 0 for the status so it appears that the call has failed even though the content is there.

    In our jQuery ajax calls this works fine because of the following piece of code in jquery.js.

    Code:
    // If the request is local and we have data: assume a success
    // (success with no data won't get notified, that's the best we
    // can do given current implementations)
    if ( !status && s.isLocal && !s.crossDomain ) {
          status = responses.text ? 200 : 404;
    }
    Any recommendations on handling this?

    Using ExtJS 4.0.7

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,111
    Vote Rating
    470
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    If you place a listener on your response, can you make the changes there?

    example ...
    Code:
    // check on success
    Ext.Ajax.on('requestcomplete', function(conn, response, options) {
    	if (response.responseText && response.status === 0) { // we have a response; used 200 for testing
    		response.status = response.text ? 200 : 404;
    	}
    	console.log(response);
    }, this);
    
    // check on exception
    Ext.Ajax.on('requestexception', function(conn, response, options) {
    // console.log(response);
    }, this);
    Please send a small working example if this does not help.

    Regards,
    Scott.

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2011
    Posts
    22
    Vote Rating
    0
    mmaltby is on a distinguished road

      0  

    Default


    This is not going to work.

    The call will count as failed and so the requestexception call back will be called.

    If you look at the logical flow of onComplete this will not work.

    Even if you modify the status, you have to recall oncomplete and even then you are missing xhr information from the request.

    Code:
    onComplete : function(request) {
            var me = this,
                options = request.options,
                result,
                success,
                response;
    
    
            try {
                result = me.parseStatus(request.xhr.status);
            } catch (e) {
                
                result = {
                    success : false,
                    isException : false
                };
            }
            success = result.success;
    
    
            if (success) {
                response = me.createResponse(request);
                me.fireEvent('requestcomplete', me, response, options);
                Ext.callback(options.success, options.scope, [response, options]);
            } else {
                if (result.isException || request.aborted || request.timedout) {
                    response = me.createException(request);
                } else {
                    response = me.createResponse(request);
                }
                me.fireEvent('requestexception', me, response, options);
                Ext.callback(options.failure, options.scope, [response, options]);
            }
            Ext.callback(options.callback, options.scope, [options, success, response]);
            delete me.requests[request.id];
            return response;
        },

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,111
    Vote Rating
    470
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    We are going to present this to Engineering for review.
    Please continue your conversation with Jasmine on ticket 7887 for the result.

    Regards,
    Scott.

Thread Participants: 1