如何使用 Trello API 创建卡片后解析响应

发布于 2024-12-29 18:56:14 字数 823 浏览 2 评论 0原文

我正在使用 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 数据吗?

I'm playing around with the Trello API and I'm slowly getting the hang of it. I'm stuck on one piece where I manage to create a new card inside a speicifc list, but I'd like to parse the response I get from the "createCard" call e.g. to get the ID of the new card.

Here is my Trello create card post:

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

I've omitted the real idList value for secutiry reasons.

I can see the card instantly on my Trello board. The response I get from this call starts like this:

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

I was expecting to see the JSON returned liked this:

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

But in this case, the JSON is wrapped around in this jQuery1510518084118841216_1327764237952 thing.

Can some tell me what the jQuery thing is for, and how do I get to the JSON data inside of it?

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

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

发布评论

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

评论(1

赠意 2025-01-05 18:56:14

由于请求将发送到另一个域(即 api.trello.com),客户端库< /a> 使用 JSONP

该库正在使用 jQuery 的 AJAX 调用(使用 jsonp 数据类型) ,这就是 JSONP 回调具有“jQuery”名称的原因。

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

我希望这样的事情应该有效:

Trello 
.post("cards", { name: "Foo", desc: "Bar", idList:"..."}) 
.done(function(card) { alert(card.id) })

Because the request is going to another domain (i.e. api.trello.com), the client-side library is using JSONP.

The library is using jQuery's AJAX calls (with the jsonp dataType), which is why the JSONP callback has a "jQuery" name.

Although the actual response you see includes the JSONP callback, the response from the library that is given to the success callback should just include the JSON.

I would expect that something like this should work:

Trello 
.post("cards", { name: "Foo", desc: "Bar", idList:"..."}) 
.done(function(card) { alert(card.id) })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文