Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext.Ajax.request sending OPTIONS request cross-domain when jQuery.ajax sends GET

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

like image 209
Mark Clancy Avatar asked May 31 '12 08:05

Mark Clancy


People also ask

Can you send an AJAX request to another domain?

Cross-origin resource sharing (or CORS) can be used to make AJAX requests to another domain.

Does AJAX support cross 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.

What is cross domain AJAX request?

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.

Is AJAX request GET or POST?

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).


1 Answers

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.

like image 67
Hans Kesting Avatar answered Oct 26 '22 01:10

Hans Kesting