4 ms·
If you type a chat message in your browser, how does it automatically show up in my browser with XMLHttpRequest?
by jshen 6y ago
If you type a chat message in your browser, how does it automatically show up in my browser with XMLHttpRequest?
- icedchai 6y agoIn old school chat rooms, this was usually done by polling for new messages every X seconds, or doing a refresh / reload of an IFrame containing the chat.
- jshen 6y agoI know, I wrote many of those, it’s a much worse solution than this.
- fzzzy 6y agoLong Polling is how we used to do it. The web page opens a request to the server but the server does not reply. Once the event happens on the server, the server replies to the old request and the client opens a new request.
- jshen 6y agoYup, this is much better than that, and nicely integrated for you.
- fzzzy 6y agoI think in Netscape 4 you could also make a request in an iframe which the server responded to with Content-Type: application/javascript and Transfer-Encoding: chunked. Then every time the server got an event it would write one chunk of javascript, which the client would execute immediately. This script could then call a callback in the parent frame.