1

I have been creating my website on a local environment and I had no problems with it. I just uploaded the files to my free host. When I visit the website I watched the Google Chrome Console and I keep getting this error:

XMLHttpRequest cannot load http://www.legobear154productions.byethost33.com/Javascript/main.json. Origin http://legobear154productions.byethost33.com is not allowed by Access-Control-Allow-Origin.

I am doing a JavaScript Ajax request with JQuery. Could anyone help me please?

legobear154
  • 431
  • 2
  • 6
  • 16

1 Answers1

1

As far as the HTTP protocol is concerned http://www.legobear154productions.byethost33.com and http://legobear154productions.byethost33.com are completely different domains. Javascript is prevented from running remote (different domain) scripts for security reasons.

You'll have to move your script to the same domain in order for it to work.

edit

There are other ways, see the page linked from the top voted answer here: A question about cross-domain (subdomain) ajax request

Community
  • 1
  • 1
Rob Allen
  • 17,381
  • 5
  • 52
  • 70
  • 2
    +1 Also, if you want both domains to work, then you can detect which domain you are on with `window.location.href` and make your Ajax requests to the same domain. – Paul May 06 '12 at 17:21
  • Thank you all! I don't know what happened but it is working now. I changed file permissions some and I don't know if that fixed it or what. I will remember that though! – legobear154 May 06 '12 at 17:22
  • @legobear154 Are you sure you didn't just switch your browser to be pointing to the `www.` version of your site? – Paul May 06 '12 at 17:24
  • Ok, I fixed it! I used window.location.host to get what I needed from the url and just used that! Thank you very much PaulP.R.O. – legobear154 May 06 '12 at 18:25
  • @legobear154 No problem, btw. To notify someone when you are responding to them put an `@` symbol in front of there name :) – Paul May 06 '12 at 21:04
  • Oh OK, I will do that next time @PaulP.R.O. :) – legobear154 May 06 '12 at 21:17