joelataylor
joelataylor

Reputation: 303

Why does jQuery say my ajax jsonp call is failing?

Not sure what I'm missing here, if you take a look at this code - you'll see I'm making a jsonp call to flickr and getting a successful response. However, jQuery always calls the 'fail' method and not the success method.

Why?

{{ EDITED }}

$.ajax({
      url: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=fun&tagmode=any',
      dataType: 'jsonp'
  })
  .done(function(data, status) {
    console.log( 'data count:', data.query.results.json.json.length );
    $('#result-count').text( JSON.stringify(data.query.results.json.json) );
  })
  .fail(function(xhr, err) {
    console.log( 'Sample of error data:', err );
    console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\nresponseText: "+xhr.responseText); });
  });

Upvotes: 0

Views: 167

Answers (1)

Kevin B
Kevin B

Reputation: 95062

It's failing because you're using the wrong jsonp callback.

...
type: 'GET',
jsonpCallback: 'jsonFlickrFeed'
...

also, in recent versions of jQuery, jsonp requests don't trigger a fail callback on error, async:false is ignored for jsonp requests, and crossDomain is not necessary (jquery sets that for you).

Upvotes: 2

Related Questions