I want to get direct exchange rates from an external source, so I found this excellent web service:
Currency Converter
This service works like a charm, the only minute is that it does not provide JSONP results, but only XML. Therefore, when trying to use this web service using jQuery $ .ajax (), we encounter a cross browser problem.
So, I found Yahoo Query Language , which returns the results as JSONP, as well as mangae, to consume other web services and return me the results. This also works, here is an example URL:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fwww.webservicex.net%2FCurrencyConvertor.asmx%2FConversionRate%3FFromCurrency%3DNOK%26ToCurrency%3DEUR'&format=json&diagnostics=true&callback=cbfunc
This URL returns a JSONP result and works like a charm, but the problem occurs when I use this in my code:
$.ajax({ type: "GET", url: urlToWebservice, contentType: "application/json; charset=utf-8", dataType: "jsonp", success: function(data) { $("#status").html("OK: " + data.text); }, error: function(xhr, textStatus, errorThrown) { $("#status").html("Unavailable: " + textStatus); } });
When I try to run this code, nothing happens and I can see this error message in my Firebug javacript debugger:
cbfunc is not defined
cbfunc is the name of the container that surrounds the JSON response, but why is it not specified?
EDIT:
This is my new code, but I still get cbfunc is not defined
$.ajax({ url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fwww.webservicex.net%2FCurrencyConvertor.asmx%2FConversionRate%3FFromCurrency%3DNOK%26ToCurrency%3DEUR'&format=json&callback=cbfunc", dataType: 'jsonp', jsonp: 'callback', jsonpCallback: 'cbfunc' }); function cbfunc(data) { alert("OK"); }
And the OK message never starts ...