0

I am trying to fetch the json string from this url: http://status.mojang.com/check

however every time i get a failure or this:

XMLHttpRequest cannot load http://status.mojang.com/check. Origin null is not allowed by Access-Control-Allow-Origin. 

Any help appreciated

<!DOCTYPE html> <html> <head>   <title>mc stats</title>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>     <meta http-equiv="Access-Control-Allow-Origin" content="*">  </head> <body>

<div id="minecraft"> </div>

<script> (function() {      var flickerAPI = "http://status.mojang.com/check?jsoncallback=?";       $.getJSON(flickerAPI)
        .done(function( data ) {
            console.log(data);  }); })(); </script> </body> </html>
Maxim
  • 3,836
  • 6
  • 42
  • 64
  • Similar question: http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin – Mike Pelley Jul 24 '13 at 16:33
  • You can check this http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin – delibalta Jul 24 '13 at 16:33
  • None of the solution fixed my problem, however when i try to fetch using the google chrome REST plugin then i get the result. I can't seem to get it working in javascript – Maxim Jul 24 '13 at 16:41
  • are you loading this page from a file? – jhamm Jul 24 '13 at 16:42
  • i am trying to load a http:// file and i am using my local computer to run the html where i wrote the javascript in – Maxim Jul 24 '13 at 16:43

1 Answers1

0

You need to run the webpage in a server and this problem should go away. There might be a way to do it with Google Chrome, but I am not aware of it. When I have this issue, I typically run my file with Aptana Studio. It is a free download and it causes the file to be served up from a server instead of just being read from your file system. It defaults to Firefox, but you can just paste the url in Chrome and everything should work like you expect, unless there are other errors.

If you are running a mac/linux you also have access to the python simple server and it should serve it up also. Run the command python -m SimpleHTTPServer from the file directory and you should be able to see it at localhost:8000. Good Luck!

jhamm
  • 24,124
  • 39
  • 105
  • 179
  • Thank you for the help, however i tried uploading it but it doesn't show anything when i log, it logs when i add the failure function, i really have no idea why – Maxim Jul 24 '13 at 17:22
  • I dont understand. Could you clarify a bit? What did you try to upload? What is the failure function you are talking about? Give us some more details so we can help out. – jhamm Jul 24 '13 at 18:24
  • Well you have the .done(function(data){}) and the .fail(function(data){}) and it logs the fail (console.log(data)) – Maxim Jul 24 '13 at 18:43
  • It is going to continue to fail until you get the `Origin null` problem fixed. You are having cross-browser sharing issues. [Here](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) is the wikipedia page. That is why I said that you view your page from a server. If you are still getting a null origin then you need to figure out that issue first. – jhamm Jul 24 '13 at 18:47
  • When i try it with "Simple REST Client" it returns me the following:Content-Encoding: gzip Server: Redstone/null Connection: keep-alive Content-Length: 112 Content-Type: application/json; charset=UTF-8 – Maxim Jul 24 '13 at 19:13
  • But from your pc, you are still getting the `Origin null`, correct? – jhamm Jul 24 '13 at 19:18
  • no i am using an external server now, and i get this error: "XMLHttpRequest cannot load http://status.mojang.com/check. Origin http://mydomain is not allowed by Access-Control-Allow-Origin. " – Maxim Jul 24 '13 at 19:21
  • I can look at it more later, but when I run the script I get the response, but it will not hit the `console.log(data)` statement. It does not error out, but for some reason it is not hitting the `.done(success)`. If you look in your network tab on your console, you will you will see the json is being returned in the response tab. It has something to do with the jsonp. I tried the test code from the Jquery site and had the same issue, so maybe there has been a change in Jquery and the docs are not updated yet. – jhamm Jul 24 '13 at 20:07