title: Using ajax to access web from local file
body: <p>i'm a bit new to JQuery and ajax, so i apologize if this is a newbie's question.</p>
  
  <p>I'm trying to use ajax from a local file to access the web (for example, getting a text file).<br>
  I'm not using IIS or anything, simple file from my hard drive (and i need it to stay that way).<br>
  Checked it on both IE8 and Chrome (version 11.0.696.60).</p>
  
  <p>Here's some javascript to illustrate:  </p>
  
  <pre><code>// use ajax to load from the web
  $("#webText").click(function(){
      $.get("http://www.w3schools.com/jquery/demo_ajax_load.txt", function(result){
          alert(result);
  });
  </code></pre>
  
  <p>This code is trying to load a text file from the web - the operation fails on both IE and chrome (won't get to get to the success function).<br>
  Chrome's notifies in the error console about <em>"XmlHttpRequest cannot load</em>  _http://www.w3schools.com/jquery/demo_ajax_load.txt: <em>Origin null is not allowed by Access-Control-Allow-Origin"</em></p>
  
  <pre><code>// use ajax to load from a local file
  $("#localText").click(function(){
      $.get("demo_ajax_load.txt", function(result){
          alert(result);
  });
  </code></pre>
  
  <p>This code is trying to load from a local text file.<br>
  IE: the operation succeeds.<br>
  Chrome: fails with same error as above.</p>
  
  <p>At this point i thought it was impossible to communicate with the web from a local file, but then i came across a similar question: <a href="https://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin">XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin</a></p>
  
  <p>Using the examples given there, I tried: </p>
  
  <pre><code>// use ajax to load json object from the web
  $("#webJSON").click(function(){
      var url = 'http://www.panoramio.com/wapi/data/get_photos?v=1&amp;key=dummykey&amp;tag=test&amp;offset=0&amp;length=20&amp;minx=-30&amp;miny=0&amp;maxx=0&amp;maxy=150';
      $.get(url, function(json) {
          alert(json.photos[1].photoUrl);
      }, "jsonp");
  });
  </code></pre>
  
  <p>And this code works great on both browsers. So obviously, it is possible to communicate with a web service from a local file.  </p>
  
  <p>Any ideas?  </p>
  
  <p>BTW - i'm more interested with the IE aspect of this, Chrome and other browsers are less of an issue.  </p>
  
  <p>Thanks.</p>