I want to do is PUSH
through jQuery when my mongodb adds an entry. I saw a lot of jQuery plugins out there, but they do LONG POLLING
not PUSH
.
I am very keen to know how this is happening here (if you will open two different windows and try to chat you will know)
This guy wrote this sample code.
He is using prototype.js
, and I saw in backend code, there is nothing special. Just MySQL select statements, but whenever the MySQL database changes prototype comet object responses to that.
Can we do something similar in jQuery? I belive this is not polling but PUSH
through prototype.js
.
Or is it like prototype is connected to socket? Sorry, I have not much idea about what sockets are, but what I really want to do is PUSH
through jQuery when my mongodb adds an entry.
Let's settle this once and for all. Since I'm not a prototype user I got to read the documentation to come up with this.
You can access the underlying XMLHttpRequestRedirected this way from your JavaScript console.
$ comet.ajax.transport.readyState
1
readyState
is 1
which stands for OPENED
.
Want to test this through? Override the XMLHttpRequestRedirected.onreadystatechanged
avoiding it to reconnect (and stay open waiting.)
$ comet.ajax.transport.onreadystatechange = function(){
console.log("Don't reconnect");
};
$ comet.ajax.transport.abort();
You'll see the Don't reconnect
message and the long-polling will be stopped.
Now try sending messages. Nothing will happen.