使用 POST 请求获取集合?
我已成功使用 REST API 来 fetch()
数据,其中 url 包含最少的参数(并使用 GET
)。
如何通过 POST
请求检索集合?
I have managed to work with REST API's to fetch()
data where the urls contain minimal parameters (and use GET
).
How would one retrieve a collection through a POST
request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另请注意,fetch 支持 Jquery.ajax 参数,因此您可以在调用中轻松设置 type = post。
更多参数:
http://api.jquery.com/jQuery.ajax/
Also note that fetch supports Jquery.ajax parameters, so you can easily set type = post in the call.
For more parameters:
http://api.jquery.com/jQuery.ajax/
您可能需要扩展 Collection 对象来安装您自己的获取约定。这样做时,您可能会提供自己的获取函数。例如:
它使用“创建”而不是“读取”。乍一看,这是我首先尝试的,尽管可能有更优雅的方法。
这种方法的缺点是您的应用程序中本质上有框架代码,如果框架发生变化,您可能会遇到问题。您最好将此更改划分到一个单独的层中,以便轻松地使用新的框架版本进行更新。
You may need to extend the Collection object to install your own convention for fetches. In doing so, you would likely provide your own fetch function. Something like:
where it uses a 'create' instead of a 'read'. On first blush, this is what I'd try first, though there may be a more elegant way to do it.
The downside of this approach is that you essentially have framework code in your app and if the framework changes you might encounter problems. You would do well to compartmentalize this change into a separate layer to make it easy to update with new framework releases.
Backbone.sync 是用于通过模型与服务器交互的函数。您可以提供自己的实现,为“read”方法发出 POST 请求,而不是 GET。请参阅http://documentcloud.github.com/backbone/#Sync
Backbone.sync is the function used to interact with the server via your models. You can provide your own implementation that issues a POST request for the 'read' method instead of GET. See http://documentcloud.github.com/backbone/#Sync