1
votes

I'm loading a json file relatively using dart's html library's HttpRequest class. In the Dart editor it's working fine. Using the dart plugin for intelliJ with JetBrains chrome extension I receive...

XMLHttpRequest cannot load file:///C:/project/web/path/to/my/file.json. Cross origin requests are only supported for HTTP.  :0
Exception: Error: NETWORK_ERR: XMLHttpRequest Exception 101
Stack Trace: #0      HttpRequest.send (file:///E:/b/build/slave/dartium-win-full-trunk/build/src/build/Release/obj/global_intermediate/webkit/bindings/dart/dart/html/HttpRequest.dart:33:3)

I'm passing a relative url, when inspecting the URL I see its: "path/to/my/file.json"

Here's the bare bones test.

import 'dart:html';

main(){
  Loader loader = new Loader();
  loader.load("someFile.json");
}

class Loader {
  load(String url) {
    var request = new HttpRequest();
    request.open('GET', url, true);
    request.send();
  }
}
1

1 Answers

0
votes

I am not sure why it works in one context and not another, but basically cannot just go GET a file if you are not using http. See these for details on why this is the case. I've never used IntelliJ, so I cannot speak to the specifics of that context, unfortunately.

http://stackoverflow.com/questions/8449716/cross-origin-requests-are-only-supported-for-http-but-its-not-cross-domain
http://stackoverflow.com/questions/3102819/chrome-disable-same-origin-policy
http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-but-im-loading-a-co