How to check database update from a browser?

4

I'm trying to make a page that updates the <div> (which has the content brought in from the database) automatically as soon as some value is entered (just like that site). I used setInterval to update (with Ajax) the <div> every 10 seconds, but I did not like the result because I find it unnecessary to make requests every ten seconds. and if you have any updates on the database run my script and update the <div>

How can I check if any values have been entered in the database?

    
asked by anonymous 12.02.2014 / 18:47

2 answers

4

The model adopted by web servers before HTML 5 is one-way requests, which in practice means that the server can never send a request to the client, just the opposite. The server can only send data to a client in response to a request.

Current Strategy: Polling

The tactic you are using is called polling , which is to ask the timeserver in if there is "something new". This tactic is the only one possible when one side can not initiate a request.

Using HTML5: Websockets

HTML 5 introduced websockets . This technology allows the client to open a two-way with the server, and therefore receive or send data at any time.

The latest standardization of websockets is 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 do bidirectional communication. This page shows a small example, with source code . The method of operation is similar to websockets - A connection to the part of the web request is opened with the server.

Using flash

It may be possible to use flash as well. I'm not sure.

    
12.02.2014 / 19:03
1
If the desired information depends on specific tables, a Trigger could be created in the respective table (I will call Table A), which, when having a record inserted, updated or removed, writes the log to another table (Table B). Your routine would query Table B to see if there was any change in the data, and if so, update your DIV.

Another way would be to schedule a JOB (SQL Server) that would verify the change of the data in Table A and this would populate Table B by signaling the occurrence of change in the database.

That's what I can see now, quickly, but there must be other ways too.

    
12.02.2014 / 18:56