title: jQuery + JSONP + Yahoo Query Language
body: <p>I want to get live currency rates from an external source, so I found this great webservice:</p>
  
  <p><a href="http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&amp;WSID=10" rel="nofollow noreferrer">Currency Convertor</a></p>
  
  <p>This service is working like a charm, the only downside is that it does not provide JSONP results, only XML. Therefore we have a cross browser problem while trying to consume this webservice using jQuery $.ajax().</p>
  
  <p>So I found <a href="http://developer.yahoo.com/yql" rel="nofollow noreferrer">Yahoo Query Language</a> which returns results as JSONP and also mangae to consume other webservices and return me the results. This is also working, here is an example URL:</p>
  
  <pre><code>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'&amp;format=json&amp;diagnostics=true&amp;callback=cbfunc
  </code></pre>
  
  <p>This URL return JSONP result and is working like a charm, but the problem appears when I use this in my code:</p>
  
  <pre><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);
    }
  });
  </code></pre>
  
  <p>When I try to run this code nothing happens, and I can see this error message in my Firebug javascript debugger:</p>
  
  <pre><code>cbfunc is not defined
  </code></pre>
  
  <p>cbfunc is the name of the container which surrounds the JSON response, but why does it say not defined?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is my new code, but I still get the <code>cbfunc is not defined</code></p>
  
  <pre><code>$.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'&amp;format=json&amp;callback=cbfunc",
    dataType: 'jsonp',
    jsonp: 'callback',
    jsonpCallback: 'cbfunc'
  });
  
  function cbfunc(data) {
    alert("OK");
  }
  </code></pre>
  
  <p>And the "OK" message is never fired...</p>