1

Working on a web app that talks to the last.fm API. For some reason, the ajax() function is not returning anything. Even though I see the app trying to talk with the API there's no callback, and even the "always" and "fail" functions fail to run. I've verified that the API key works fine. Not sure what's going on...

Here's the call, simplified for the purposes of this question:

 $.ajax({
    type: 'GET',
    url: 'http://ws.audioscrobbler.com/2.0/',
    contentType: "application/json; charset=utf-8",
    dataType: 'jsonp',
    data: {artist: 'cher', track: 'believe', method: "track.search", api_key: '(my key here)', format: 'json'},
done: function() {
  alert('done')
},
fail: function() {
  alert('fail')
},
always: function(data) {
     alert('always')
     try{
     var matches = data['results']['trackmatches']['track'][0]
     console.log(data)
     }
     catch(err) {
      returned = data['results']['opensearch:Query']['searchTerms']
      $('#album-display').find('ul').append(returned + "<br>")
     }
  }
});
Ben Davidow
  • 1,175
  • 5
  • 23
  • 51
  • 1
    Are there any errors in your console or network tab? Also, you'll need to use jsonp for remote ajax. – Jason P Jul 26 '13 at 18:00
  • Yep, no errors in the console or network. Good point, can I simply change the datatype to 'jsonp'? – Ben Davidow Jul 26 '13 at 18:07
  • Not sure. Try it and see. – Jason P Jul 26 '13 at 18:08
  • Tried, but still not working... – Ben Davidow Jul 26 '13 at 18:16
  • You said there aren't any errors on your network tab. Do you see the xhr request? What is the response? – Jason P Jul 26 '13 at 18:19
  • Here's the response I see in the network tab: HTTP/1.0 200 OK Server: Apache/2.2.22 (Unix) X-Web-Node: www224 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: POST, GET, OPTIONS Access-Control-Max-Age: 86400 Cache-Control: max-age=86400 Expires: Sat, 27 Jul 2013 18:20:32 GMT Content-Type: text/javascript; charset=utf-8; Content-Encoding: gzip Date: Fri, 26 Jul 2013 18:20:32 GMT X-Varnish: 2205551160 Age: 0 Via: 1.1 varnish Connection: close X-cms: 1 X-varnish-host: varnish3 – Ben Davidow Jul 26 '13 at 18:22

0 Answers0