A complete backbone noob question.
I was wondering, is there a way to listen to HTTP-POST events in backbone?
Lets say, when an API user does a POST
request using wget
from the command line I would like to update my view. I looked at the API docs and I tried the request
option but had no luck. Basically in my view I am trying something like this:
this.listenTo(this.collection, 'request', this.render);
PS: I have the function definition of this.render
in my code
除非服务器使用某种服务器推送技术明确通知客户端有关事件,否则一个客户端无法监听另一客户端的事件。
I'm just going to extend on @Yaroslav's answer. His answer is totally correct; you cannot explicitly do what you want. Your workflow would have to go something like this:
In terms of your server push technology, you have a few different options.
All of these are touched upon and explained in this blog post .
A brief summary:
Polling
Polling is when your web app asks your server for new information at a given interval. Ie, every 10 seconds your Backbone application asks if anything new has happened. This can give a max latency of your interval time, and can lead to alot of unnecessary requests
Long polling
Your client always maintains an open request to the server, which is not returned until something happens. At that time, your client can act on the new information, and then makes a new request, which again stays open until new information.
Websockets
Websockets are a bidirectional transport mechanism which enables server->client and client->server messages.
Server Sent Events
Server sent events are a uni-directional transport and part of the HTML5 spec. They allow server->client messages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.