3

I have found that many had similar problem:

XMLHttpRequest cannot load %3192.168.100.201:8080/history?_=1400139870373. Cross origin requests are only supported for HTTP.

I have tried to start the browser like:

--disable-web-security
--allow-file-access-from-files

How can I get the JSON file from server on local network?


Update

JS code:

function getHistory() {
        $.ajax({
            url: '192.168.100.201:8080/history',
            dataType: 'json',
            success: function(data) {
                console.log(data); 
            },
            cache: false
        });
     }
Filip Luchianenco
  • 6,912
  • 9
  • 41
  • 63
  • 2
    It is forbidden in modern browsers. In older browsers it does work. To get around you should write some server-side code to return the file and call that with the JavaScript. – devqon May 15 '14 at 07:56
  • What if i request from a php file which returns the same json from server on local network? shortly: js requests json from local php > php requests json from server – Filip Luchianenco May 15 '14 at 07:58
  • those answers does not help. Also I get json from another machine on local network, not same machine. So the accepted answer does not help, and the second answer is mentioned in my question. – Filip Luchianenco May 15 '14 at 08:02
  • @FilipLuch: Are you sure? You still need to specify a valid URL. Have you tried that? `192.168.100.201:8080/history` does not look like a valid `http://` URL. the solution on the other post suggests the use of a valid URL. I would assume your issue is solved the same way by having a valid `http://xx` URL? – Nope May 15 '14 at 08:04
  • I updated the question, you can see the actual URL. – Filip Luchianenco May 15 '14 at 08:06

1 Answers1

3

Cross origin requests are only supported for HTTP.

This is because you forgot http:// in your request:

url: 'http://192.168.100.201:8080/history',
  • The browser does not know what protocol you want.

You should also send an access control header (read about Cors [1]) from the targeted serverside:

Access-Control-Allow-Origin: http://<requesting host>

Not a must in every case, but a good practice and security feature by modern browsers.

[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Thanks. This worked. At first i got `No 'Access-Control-Allow-Origin' header is present on the requested resource.` and then changed the server side as mentioned here: http://stackoverflow.com/questions/22181384/javascript-no-access-control-allow-origin-header-is-present-on-the-requested/22182390#22182390 – Filip Luchianenco May 15 '14 at 08:15