最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

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

Share Improve this question asked May 31, 2012 at 8:55 Mark ClancyMark Clancy 7,8898 gold badges45 silver badges51 bronze badges 1
  • my problem too ! any luck finding the solution ? @CL4NCY – Duke Commented Jun 4, 2012 at 8:47
Add a comment  | 

3 Answers 3

Reset to default 11

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.

Set

Ext.Ajax.useDefaultXhrHeader = false

Before

    Ext.Ajax.request({
        url: 'www.yourUrl.com',
        .....
    });

Or you can set with method like this :

Ext.Ajax.setUseDefaultXhrHeader(false);
Ext.Ajax.request({
                    url: "http://yoururl.domain",
                    success: function(response, eOpt) {
                        console.log('success');
                    },
                    failure: function(response, eOpt) {
                        console.log('error');
                    }
                });
发布评论

评论列表(0)

  1. 暂无评论