开发者

How do I stop browser from 'waiting' for Node.js callback

开发者 https://www.devze.com 2023-03-09 22:41 出处:网络
I am creating an Express JS app on Node.js and have implemented a page that will callback for live updates as per chat.nodejs.org (https://github.com/ry/node_chat). I\'ve followed the approach in \'no

I am creating an Express JS app on Node.js and have implemented a page that will callback for live updates as per chat.nodejs.org (https://github.com/ry/node_chat). I've followed the approach in 'node_chat' to a t, and the page updates correctly if an update is made from another browser. The only problem is I can't seem to stop the browser (Chrome) from 'Waiting for localhost' and spinning away, which I don't think it needs to do.

Here's simplified versions of my code (for brevity). Any ideas?

client.js (client side):

function 开发者_JAVA百科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);
  });

});

it doesn't seem to matter what I put in the queueProvider.query method, it will spin away until res.send(...) is executed.

I used https://github.com/ry/node_chat/blob/master/client.js and https://github.com/ry/node_chat/blob/master/server.js for reference.

Particularily:

fu.get("/recv", function (req, res) {...}

and

channel.query()

and

channel.appendMessage()

Thanks.


I would recommend that to avoid this spinning icon, you switch from polling to something like WebSockets (e.g. http://socket.io)

0

精彩评论

暂无评论...
验证码 换一张
取 消