On my website i have a banner which now changes as you reload the page.
I would like a add a button 'Shuffle' and make a random image appear, via Ajax. I have started this imagemodule and made something working. However, when i click the 'shuffle' button, i'm not getting 1 new image, the image keep changing untill i press esc.
How my module looks like now: (btw, 'foto' is dutch for 'picture')
BannerFoto.module.php
- Containts a function init()
Checks for pictures in a directory and generates an (shuffled) array in $_SESSION['fotos'] - Contains a function MaakFoto()
Picks a random image from session and echoes html:
- Checks whether $_SESSION['fotos'] is set. If not run $this->init()
- Run $this->MaakFoto();, this displays the photo on page acces
- Register Ajax requester:
$ajax->RegisterAjaxRequester($this->GetName(), 'bnnr','fpbanner','MaakFoto',false,array(), array(),-1);
I call these functions from a content page, using
Code: Select all
<div id="fpbanner">
{cms_module module="BannerFotos"}
</div>
<span onClick="return makeBannerFotosbnnrRequest();">Klik!
</span>
Code: Select all
function makeBannerFotosbnnrRequest() {
var http_request=gethttp();
http_request.onreadystatechange = function() { alertBannerFotosbnnr(http_request,true); };
http_request.open('GET', 'http://www.nsrvphocas.nl/modules/AjaxMadeSimple/requesthandler.php?module=BannerFotos&method=MaakFoto&', true);
http_request.send(null);
}