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

Mark Clancy picture Mark Clancy · May 31, 2012 · Viewed 8k times · Source

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

Answer

Hans Kesting picture Hans Kesting · Jun 6, 2012

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.