Check database in real time with Javascript

Asked

Viewed 639 times

-3

I wanted to make a system where we have a blank page and when something was placed in a table of the database Javascript automatically displayed the result on the page without giving refresh, ie without giving F5 on the page.

How do I do that?

  • search on ajax cron job, to get information for what you need.

  • Search by [tag:ajax].

  • This is related to Long Polling : http://answall.com/questions/9475/notifies%C3%A7%C3%B5es-in-real-time-similar-to-stack-overflow/10109#10109

1 answer

2

You can try the following: Use the method setInterval() to call a script via AJAX every X period. Ajax content can be loaded anywhere on the page without the need to reload it, inside a div for example.

One way to implement this is to create two files:

A - a main html file, which will contain the DIV where the AJAX content will be loaded and the javascript code that will call AJAX every X period of time.

B - a php file that will be called via ajax and that will query and return the contents of the database.

I hope I’ve helped!

  • Good afternoon, can you give me an example of code?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.