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]);
};
gallery.php? Also, try to get this in a Javascript array...so that you can just replace the values from the array...no need of ajax as well.