I have a <body style="<?php include("gallery.php"); ?>" where gallery.php holds a random array of images, echoing the URL upon each reload.
I would like to have a button to refresh the background image of the body.
I currently am able to do one reload of the image, since the new URL is echoed.
EG:
$(".refresh").click(function() {
$("body").css("background-image", "url(<?php include("gallery.php"); ?>)");
});
But after the inclusion of the gallery file in the script, it is always the same url.
EDIT
My PHP is as follows:
$bg = array(
array( "url" => "url_1" ),
array( "url" => "url_2" ),
...
);
for ($i=0;$i<1;$i++) {
$id = array_rand($bg);
echo "{$bg[$id]['url']}";
unset($ad[$id]);
};
It would be in an another way and
gallery.phpcould outputs an image (not just a url), So you can accessgallery.phplike this :Using
Math.random()will passes a random number to avoid caching.So in
gallery.phpyou have something like :