I am populating a js array thanks to php every 2 seconds but it works only the first time because the php code is executed only when I open the window but I want to execute it every time I launch the js function.
Here is my code :
function update(){
var datas = <?php echo Gallery::getPhotos(); ?>;
...
}
setInterval( "update()", 2000 );
The problem is that the var datas
never changes because <?php echo Gallery::getPhotos(); ?>;
is executed only the first time. How can I do to execute the php every 2 seconds ?
I saw solutions with doing a request on a file but I don't know how to do and I don't know if this is the solution for only 1 instruction.
Gallery
is a singleton class which stores pictures, the function getPhotos()
returns an array with photos names.