tags:

views:

397

answers:

2

So, here's my JSONP URL:

http://community.tradeking.com/leaderboard.js

And here's the jQuery I'm trying to parse it with:

$.ajax({
  dataType: 'jsonp',
  jsonp: 'callback',
  url: 'http://community.tradeking.com/leaderboard.js?callback=?',
  success: function () {
    alert("something");
  },
});

And here's the error I'm getting in Firebug:

processLeaderboard is not defined

I've also tried getJSON and the jQuery JSONP specific plugin, but they all fail in similar ways. The JSONP is being used successfully elsewhere.

+2  A: 

You need a function that is called processLeaderboard, since that function name seems hardcoded into the response from your link.

var processLeaderboard = function (data) {
  alert('Do your stuff here');
}

$.ajax({
  dataType: 'jsonp',
  jsonpCallback: 'processLeaderboard',
  url: 'http://community.tradeking.com/leaderboard.js?callback=?',
  success: function () {
    alert("something");
  },
});
PatrikAkerstrand
Doesn't seem to work. I'm still getting "processLeaderboard is not defined".
ahow
Use jsonpCallback: 'processLeaderboard' instead of jsonp: 'processLeaderboard'
Tim R
A: 

This worked just fine for me in jsbin using chrome.

var processLeaderboard = function(x) {
  alert(x[0].member.avatar.public_filename);
};

$(document).ready(function() {

   $.ajax({
     dataType: 'jsonp',
     jsonp: 'processLeaderboard',
     url: 'http://community.tradeking.com/leaderboard.js?callback=?'

   });
});​
Hogan