0

i would like to alert webservice JSON response from this url http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&&callback=? , how to do this,any idea?

I tried this below , but its not working at all.

 $(document).ready(function () {

    var b = "http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&&callback=?";
    //var b= "http://finance.yahoo.com/connection/currency-converter-cache?date=20150307";   // or this url also
    $.getJSON(b, function (e) {
    alert(e);
 });

}) 

FIDDLE


UPDATE: An Error shown on browser console

XMLHttpRequest cannot load http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&&callback=?. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
user2173803
  • 53
  • 2
  • 8
  • Your fiddle is just a link to the jsfiddle homepage. As for your Yahoo link, it is returing JSON. The only bug I can see in your code is possibly the `$.getJSON` function might not work with JSONP, but I would have to look more into that – Jason Sperske Mar 14 '15 at 19:42
  • I don't think you'd have any luck as yahoo doesn't seem to support `JSONP` – lshettyl Mar 14 '15 at 19:48
  • @JasonSperske i have updated my question. any tips to get json response please – user2173803 Mar 14 '15 at 19:49
  • It means you can't request finance.yahoo.com from any other origin. Once solution might be going through yql it solves cross-orgin problem or you can give try from server side request. – Zeeshan Hassan Memon Mar 14 '15 at 20:13
  • A common way around this is to make the web request in your server-side code so that it is not script, and therefore not constrained by the same origin policy. Then, you expose that as a service that you can call from script because it is in your own domain. – Crowcoder Mar 14 '15 at 20:28
  • @ZeeshanHassanMemon But the same way this site is using & its getting result, what is the magic behind this could not able to know, any help ? THis website: view-source:http://currency.fullstacks.net/ (tips: search "yahoo" in view source page, You can use javascript beautifier to view code http://jsbeautifier.org/ ) – user2173803 Mar 14 '15 at 20:29

1 Answers1

0

There is probably a way to access the Yahoo API with JSONP over YQL but I think it's better to use some other service.

It seems that Yahoo isn't supporting that API. See this SO question.

I searched for an exchange rate json api at google and I've found fixer.io which is working. See this fiddle and below.


Update 14.03.2015 21:09 (UTC)

Please have a look at this jsFiddle it's a demo to access the Yahoo API. I had to add the env to all databases to be able to access the news feed for the demo. You probably can change the YQL to access the data you want.

The YQL console is very helpful to see what data are available. You can access the console here.

The code is from this page. The initial code was not working because it couldn't find the search.news table. Probably because of the env property but I need to check that.

$(function() {
    $.ajax({
        url: "http://api.fixer.io/latest",
        dataType: "jsonp",
        jsonp: "callback",
        success: function(response) {
            $(".json").text(JSON.stringify(response, null,2));
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre class="json"></pre>
Community
  • 1
  • 1
AWolf
  • 8,770
  • 5
  • 33
  • 39