我正在Node.js上创建一个Express JS应用程序,并且实现了一个页面,该页面将根据chat.nodejs.org(https:/ /github.com/ry/node_chat)。我已将'node_chat'中的方法跟踪到t,并且如果从另一个浏览器进行更新,页面会正确更新。唯一的问题是,我似乎无法阻止浏览器(Chrome)从'等待本地主机'并转移,我认为它不需要做。如何停止浏览器等待Node.js回调
这是我的代码的简化版本(为简洁起见)。有任何想法吗?
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);
}
});
};
app.js:
app.get('/json-people', function (req, res) {
queueProvider.query(req.param('slug'), req.param('since'), function (people){
res.send({people: people}, 200);
});
});
它似乎没有什么事我放在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) {...}
和
channel.query()
和
channel.appendMessage()
感谢。
这是预期。它旋转,因为它正在加载。使用websockets。 – Raynos 2011-06-02 23:48:44