Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext.Ajax.request() invokes the failure callback function upon successful request

I'm building a PhoneGap - Sencha-touch application for the iOS and Android platforms. I am loading a local .js file using the Ext.Ajax.request() function.

Funny thing happens - the requests succeeds, but the the 'failure' callback is called. Here is the code:

   Ext.Ajax.request({
       url: 'localfolder/foo.js',
       success : function(xhr){
           // not invoked
       },
       failure : function(response, options){ 
           // response.status == 0
           // wtf, response.responseText contains exactly the contents of the local .js file!
       }
   });

Anyone has an Idea why the 'failure' callback is triggered when in fact the request succedded? [edit] More importantly, how do I make the 'success' callback to be triggered instead?

like image 559
gardenofwine Avatar asked Jan 18 '23 22:01

gardenofwine


1 Answers

Ext.Ajax simply examines the status code of the underlying XHR (XmlHttpRequest) object it creates. However, it (incorrectly) assumes that the status is an HTTP status. As this Mozilla-provided article discusses, when file: or ftp: schemes are used, a status value of 0 indicates success.

You can modify the onComplete function in Ext.data.Connection (in src/data/Connection.js) to look at the scheme of the URL, and decide if it should use an HTTP-based status or a "0=OK" status to determine success.

It is perfectly legal for non-success results to have a body that can be used by the client. This is why your response.responseText still shows up correctly.

like image 165
mmigdol Avatar answered Jan 30 '23 23:01

mmigdol