3

我正在使用Trello API,我正在慢慢掌握它。我被困在一个我设法在特定列表中创建一张新卡的地方,但我想解析我从“createCard”调用中得到的响应,例如获取新卡的 ID。

这是我的 Trello 创建卡片帖子:

Trello.post("cards", { name: "Card Created from MVC", desc: "This is the description of the card.", idList: "??????????" }).done(onCardCreated());

idList出于安全原因,我省略了真正的价值。

我可以立即在我的 Trello 板上看到这张卡片。我从这个电话中得到的回应是这样开始的:

jQuery1510518084118841216_1327764237952({"id":"????","name":"Card Created from MVC","desc":........)

我期待看到返回的 JSON 是这样的:

{"id":"????","name":"Card Created from MVC","desc":....}

但是在这种情况下,JSON 被包裹在这个jQuery1510518084118841216_1327764237952东西中。

有人能告诉我 jQuery 的用途是什么,以及如何获取其中的 JSON 数据吗?

4

1 回答 1

6

因为请求将发送到另一个域(即 api.trello.com),所以客户端库使用JSONP

该库使用jQuery 的 AJAX 调用(使用jsonpdataType),这就是 JSONP 回调具有“jQuery”名称的原因。

尽管您看到的实际响应包括 JSONP 回调,但库中提供给成功回调的响应应该只包括 JSON。

我希望这样的事情应该起作用:

Trello 
.post("cards", { name: "Foo", desc: "Bar", idList:"..."}) 
.done(function(card) { alert(card.id) })
于 2012-01-28T17:37:10.300 回答