I have a Sencha Touch application calling my web service cross-domain using Ext.Ajax.request. As I have built the web service I've enabled it to access cross-domain requests. However Ext sends an OPTIONS request first as a handshake then a GET request whereas jQuery.ajax just sends a GET request. Due to circumstances outside my control the hosting provider doesn't support OPTIONS requests. At the moment I have resorted to using jQuery for ajax requests and Sencha Touch for the rest of the application. I don't really want to have to load the jQuery library just for this.
Can anyone shed some light on why Ext.Ajax sends an OPTIONS request and is there a way to make it just send a GET?
Thanks
Cross-origin resource sharing (or CORS) can be used to make AJAX requests to another domain.
For a successful cross-domain communication, we need to use dataType “jsonp” in jquery ajax call. JSONP or “JSON with padding” is a complement to the base JSON data format which provides a method to request data from a server in a different domain, something prohibited by typical web browsers.
CORS is a mechanism that defines a procedure in which the browser and the web server interact to determine whether to allow a web page to access a resource from different origin. Figure 2. Cross domain ajax request. When you do a cross-origin request, the browser sends Origin header with the current domain value.
GET vs POST in AJAX callsUnless you are sending sensitive data to the server or calling scripts which are processing data on the server it is more common to use GET for AJAX calls. This is because when using XMLHttpRequest browsers implement POST as a two-step process (sending the headers first and then the data).
In the Ext.Ajax.request
config, set useDefaultXhrHeader
to false. This will prevent the extra OPTIONS request.
According to the docs:
Set this to false to not send the default Xhr header (X-Requested-With) with every request. This should be set to false when making CORS (cross-domain) requests.
My experience is that the OPTIONS call disappeared, I got the POST verb I expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With