我正在Node.js上创建一个Express JS应用程序,并根据chat.nodejs.org(https://github.com/ry/node_chat)实现了一个将回调实时更新的页面.我已经按照'node_chat'中的方法进行了操作,如果从其他浏览器进行更新,页面会正确更新.唯一的问题是我似乎无法阻止浏览器(Chrome)从'等待本地主机'和旋转,我不认为它需要做.
这是我的代码的简化版本(为简洁起见).有任何想法吗?
client.js(客户端):
function poll(data) {
// ...
if(data){
// do something with the data
}
$.ajax({
cache:false,
type:'GET',
url:'/json-people',
dataType: 'json',
data: {
slug: queue.slug,
since: CONFIG.last_timestamp
},
error: function () {
// handle error
},
success: function (data) {
poll(data);
}
});
};
Run Code Online (Sandbox Code Playgroud)
app.js:
app.get('/json-people', function (req, res) {
queueProvider.query(req.param('slug'), req.param('since'), function (people){
res.send({people: people}, 200);
});
});
Run Code Online (Sandbox Code Playgroud)
我把它放在queueProvider.query方法中似乎并不重要,它会一直旋转,直到执行res.send(...).
我使用https://github.com/ry/node_chat/blob/master/client.js 和https://github.com/ry/node_chat/blob/master/server.js作为参考.
Particularily:
fu.get("/recv", function (req, res) {...}
Run Code Online (Sandbox Code Playgroud)
和
channel.query()
和
channel.appendMessage()
Run Code Online (Sandbox Code Playgroud)
谢谢.
| 归档时间: |
|
| 查看次数: |
1177 次 |
| 最近记录: |