jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 269 forks source link

Can this work for file:// without webserver and network #144

Closed JennieJi closed 9 years ago

JennieJi commented 9 years ago

Hi, basically I met an issue similar to this: https://docs.angularjs.org/api/ng/directive/script
The problem can be described as to make Angular template loaded in an environment without local webserver and network in IE9.
So I try to find solution everywhere including xdomain and xhook, seems not working. That means I want master and slave be the same in local. Is it possible?

jpillora commented 9 years ago

XDomain shouldn't be any different, here's a cut down version of demo page which should work from the file:// domain:

<!DOCTYPE HTML>
<html>
<body>

  <a href="https://github.com/jpillora/xdomain">
    <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>

  <h3>XDomain Demo</h3>
  <p>
    Cross-domain XHR access to Amazon (http://s3.amazonaws.com)<br>
    From '<span id="host"></span>'<br>
  </p>

  <script src="https://rawgit.com/jpillora/xdomain/gh-pages/dist/xdomain.js"
          slave="http://s3.amazonaws.com/jpillora-usa/xdomain/0.6/proxy.html"></script>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

  <h5>Cross domain 'http://s3.amazonaws.com/jpillora-usa/data2.json'</h5>
  <p><i>XHRs will be intercepted and silently sent over to a hidden iframe</i></p>
  <pre id='cross'>Loading...</pre>

  <script type="text/javascript">
    //show current origin
    $("#host").html(xdomain.origin);
    //jquery ajax call
    $("#cross").load('http://s3.amazonaws.com/jpillora-usa/xdomain/data2.json');
  </script>

</body>
</html>

I'd say get a local file server if you're able, download node then "npm i -g serve", then just run "serve" where you need a server

jpillora commented 9 years ago

That means I want master and slave be the same in local. Is it possible?

Your slave is your API server, it should be a running HTTP server, it can be live or on localhost. Though, it doesn't make sense for it running over file:// since you can't make XHR requests to file:// URLs.

JennieJi commented 9 years ago

Sorry I gave a wrong url for my problem, it's http://stackoverflow.com/questions/26115555/loading-angular-in-ie-from-file-system
Well, hmmm... I know XHR is not allowed by security. Thanks for replying.