-
26 Apr 2012 8:09 AM #1
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.
Any recommendations on handling this?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; }
Using ExtJS 4.0.7
-
26 Apr 2012 3:21 PM #2
If you place a listener on your response, can you make the changes there?
example ...
Please send a small working example if this does not help.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);
Regards,
Scott.
-
27 Apr 2012 7:26 AM #3
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; },
-
3 May 2012 9:09 AM #4
We are going to present this to Engineering for review.
Please continue your conversation with Jasmine on ticket 7887 for the result.
Regards,
Scott.


Reply With Quote