Search code examples
jqueryjsonsame-origin-policystock

web scraping same origin policy problem preventing access


Trying to write a simple call to google's JSON stock ticker API. I would like to get JSON, however, the same origin policy comes up. Any ideas of how to work around this? I've heard of using an iFrame, but was hoping for something simpler or more elegant.

Here is my call:

$('#ticker').change(function() {
      url = "http://www.google.com/finance/info?client=ig&q=" + this.value;
      $.getJSON(url, function(data) {
          alert(data);
        });
});

Any help is much appreciated!


Solution

  • Put the data in your page before you serve it up. Make a server-to-server XMLHTTP call. Alternately there is JSONP:

    http://api.jquery.com/jQuery.getJSON/