-
22 Mar 2012 7:28 AM #1
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:
Results on mobile safari running iOS 5.0.1 are the same.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
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?
-
22 Mar 2012 7:49 AM #2
try to listen on the requestexception see docs
http://docs.sencha.com/touch/2-0/#!/...questexceptiontrainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
22 Mar 2012 7:54 AM #3
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.
-
22 Mar 2012 8:04 AM #4
if you get an 404 error the event should be firedCode:Fires if an error HTTP status was returned from the server. See HTTP Status Code Definitions for details of HTTP status codes.
just try
HTML Code:Ext.Ajax.request({ listeners: { requestexception: function() { log_msg('requestexception'); } }, ..trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
22 Mar 2012 9:32 AM #5
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.
-
26 Mar 2012 9:18 PM #6
I've exactly the same problem...
So anybody got a solution ?
-
27 Mar 2012 4:20 AM #7
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;
}
});


Reply With Quote