尝试解析 JSONP 时 jQuery 和 $.ajax 出现问题

发布于 2024-08-23 17:01:55 字数 557 浏览 3 评论 0原文

所以,这是我的 JSONP URL:

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

这是我试图解析它的 jQuery:

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

这是我在 Firebug 中遇到的错误:

processLeaderboard 未定义

我也尝试过 getJSON 和 jQuery JSONP 特定插件,但它们都以类似的方式失败。 JSONP 已在其他地方成功使用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陈独秀 2024-08-30 17:01:55

您需要一个名为 processLeaderboard 的函数,因为该函数名称似乎已硬编码到链接的响应中。

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");
  },
});

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");
  },
});
塔塔猫 2024-08-30 17:01:55

这对我来说在使用 chrome 的 jsbin 中工作得很好。

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=?'

   });
});​

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=?'

   });
});​
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文