Reflecting database changes without reloading the page in PHP

I am creating a photo sharing service in php. I use lightbox in jquery that will pop up when we click the "Add" button to add photos. We can upload some photos. I also use ajax to upload photos so that the page does not reload. I want that after I have uploaded the photos, they will be automatically uploaded to my gallery, and the gallery should display new photos without refreshing the page. Photos will have a specific identifier for a specific user in the database, so the change in the table for the user should be explicitly reflected. Now the problem is that I have no control over the lightbox close button. Therefore, I cannot change it to call any other function, so that it executes the request and displays my photos using ajax.I heard that we can automatically detect changes to the database using JSON, but I never used JSON and knew almost nothing about it. Can someone illustrate a simple example in php of how changes can be detected in mysql table using JSON? Is there any other way to achieve it? Please help me.

+3
source share
1 answer

JSON is an ideal data exchange language. JSON is used only for fast data exchange. You cannot do this without the help of a DOM request. http://www.json.org/

You can do this with ajax. You make an ajax request every second for the latest update.

or

use a long polling method like a comet

Deploy COMET with PHP

EDIT: - gowri: How to make ajax request per second?

use setInterval

setInterval (function () {

// make your ajax call here

}, 1000);

+1
source

All Articles