23

I by chrome->Inspect element->console get this error:

XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin.

What is this resolved?

Pavel Chuchuva
  • 22,633
  • 10
  • 99
  • 115
Kate Thompson
  • 443
  • 2
  • 7
  • 13
  • See http://en.wikipedia.org/wiki/Same_origin_policy for background. If you are looking for a workaround, you need to add more details about what you are doing. – Pekka Aug 23 '11 at 07:16
  • 1
    The server isn't allowing cross-origin requests. Background info: http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing – sethobrien Aug 23 '11 at 07:17
  • [i hope can help you][1] [click][2] [1]: http://stackoverflow.com/questions/3828982/xmlhttprequest-cannot-load-an-url-with-jquery [2]: http://stackoverflow.com/questions/22230520/no-access-control-allow-origin-header-is-present-on-the-requested-resource-node it's idea... – Cherryishappy Sep 22 '15 at 03:55

3 Answers3

17

You cannot issue requests through the XMLHttpRequest to other domains or subdomains. If you are issuing the request from www.foo.com you also need to target the request at www.foo.com and not leave out the www.

If you really need to hit another domain you can use JsonP where the browser utilizes the <script> tags ability to load scripts from a different domain. The loaded script then executes a callback function to give you the data. But for regular AJAX calls you cannot leave the source domain at all.

See the Wiki article on Same Origin Policy

Tigraine
  • 23,358
  • 11
  • 65
  • 110
5

one work around is using Korz which routes all cross origin requests through a third party and sets Access-Control-Allow-Origin header to '*' so the request goes through.

yonatan
  • 595
  • 1
  • 4
  • 18
3

I recommend you to read this: http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/

It is very wel explained... the whole point is that you need to return your JSON in a callback-function way

beitomartinez
  • 53
  • 2
  • 8
  • getting a database error on this link, can you please give updated link, if you have one – Ray Aug 06 '13 at 02:46