I am building a photo sharing service in php. I am using a lightbox in jquery which will popup when we click 'add' button to add photos. We can upload multiple photos. Also I am using ajax to upload photos so that the page is not reloaded. I want that after I upload photos the same will be automatically loaded in my gallery and the gallery should display new photos without need to refresh the page. The photos will have a particular id for a particular user in the database, so ulitmately the change in the table for the user should be reflected. Now the problem is that I don't have control over the closing button of the lightbox. Therefore I cannot modify it to call any other function so that it performs the query and displays my photos using ajax. I have heard that we can detect changes in the database automatically using JSON, but I have never used JSON and know almost nothing of it. Can anyone illustrate a simple example in php of how can the changes in a mysql table detected using JSON? Is there any other way to achieve it? Please help me.
Asked
Active
Viewed 2,024 times
1 Answers
1
JSON an ideal data-interchange language.JSON is used for fast data interaction only.so you can not do this with out help of DOM request. http://www.json.org/
You can do this with ajax. You make ajax request for every second for latest update.
or
use long polling method like comet
EDIT:- gowri:How to make ajax request per second?
use setInterval
setInterval(function(){
//make your ajax call here
},1000);
-
How to make ajax request per second? Does it affect the interface? I mean does the user get a sense that the gallery is refreshed now and then? – Sanks R May 12 '11 at 04:35
-
check update answer. do you want to show the gallery is refreshing to user – Gowri May 12 '11 at 04:45
-
than no problem.use JSON and get records in array format,with that array draw your page. live example is here http://www.beezid.com/.use firfug to see the response – Gowri May 12 '11 at 04:57