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

javascript - What is the impact of having $.support.cors = true; on Non-Cross browser ajax calls - Stack Overflow

programmeradmin1浏览0评论

All,

I have a need to make cross-domain AJAX requests and hence added "$.support.cors = true;" line before my ajax requests.

But for non cross-domain calls, my ajax doesn't seem to hit.

Does this "$.support.cors = true;" has impact on the non cross-browser calls or am i seeing something wrong?

Any help is much appreciated! Thanks

All,

I have a need to make cross-domain AJAX requests and hence added "$.support.cors = true;" line before my ajax requests.

But for non cross-domain calls, my ajax doesn't seem to hit.

Does this "$.support.cors = true;" has impact on the non cross-browser calls or am i seeing something wrong?

Any help is much appreciated! Thanks

Share Improve this question asked Mar 6, 2013 at 18:08 Jegan KunniyaJegan Kunniya 9923 gold badges18 silver badges28 bronze badges 4
  • You'll get a better response if you define "doesn't seem to hit". Do you get errors? Does the response actually get loaded (check the network tab in your console)? What's the actual problem you're encountering? – nrabinowitz Commented Mar 6, 2013 at 18:13
  • setting $.support.cors to true doesn't do anything other than trick jQuery into thinking that all browsers fully support CORS, which is not true. IE < 10 does not support CORS in the same way that the other browsers do, therefore CORS will not work in IE< 10 in jQuery unless you extend jQuery. – Kevin B Commented Mar 6, 2013 at 18:19
  • The only time you should use $.support.cors = true is if you're using an environment where cors is supported but jQuery incorrectly detects that it isn't, such as phonegap. – Kevin B Commented Mar 6, 2013 at 18:26
  • @nrabinowitz, "doesn't seem to hit" means, that the request doesn't happen to the server. But the error might have been missed as I was not caching it till i read your ment. – Jegan Kunniya Commented Mar 6, 2013 at 18:58
Add a ment  | 

1 Answer 1

Reset to default 3

As others have said, jQuery should detect CORS requests appropriately by default. Sounds like you should not set $.support.cors. The problem you are probably running into, without setting that, may be one of the following:

  • The server you're hitting needs to allow CORS: it needs to put a header Access-Control-Allow-Origin with the specified Origin in the request header, or *, when returning the data; otherwise your browser will reject it.

  • IE8/9 doesn't allow CORS by default using jQuery, so you need to use this plugin:

    https://github./MoonScript/jQuery-ajaxTransport-XDomainRequest

发布评论

评论列表(0)

  1. 暂无评论