The model adopted by web servers before HTML 5 are one-way requests, which in practice means that the server can never send a request to the client, only the other way around. The server can only send data to a client in response to a request.
Current strategy: Polling
The tactic you’re using is called Polling, which consists in asking the server from time to time if "there is something new". This tactic is the only one possible when one side cannot initiate a request.
Using HTML5: Websockets
HTML 5 has introduced websockets. This technology allows the client to open a bidirectional with the server, and therefore receive or send data at any time.
The latest standardization of websockets is the rfc6455 and is supported by the following browsers:
- Internet Explorer 10+
- Mozilla Firefox 4+
- Safari 5+
- Google Chrome 4+
- Opera 11+
If it is possible for your application to limit itself to these browsers, you can use websockets.
Using JAVA
It is also possible to use a Java applet to make two-way communication. This page shows a small example, with source code. The working method is similar to websockets - A connection to the web request part is opened with the server.
Using flash
You might be able to use flash as well. I’m not sure.
Honestly this is the most wrong way to make an asynchronous request. I recommend you study Websockets. http://www.html5rocks.com/pt/tutorials/websockets/basics/.
– Luiz Picolo
I know this is the wrong way, so I asked for help, thanks @Luizpicolo! , I will give a study yes :D
– Odair