WikiJuanan: AjaxMadeSimple ...

Inicio | Indice De Paginas | Ultimas Modificaciones | Ultimos Commentarios | Usuarios | Registrarse | Conectar:  Contraseña:  
Esto es una version antigua de AjaxMadeSimple de 2008-06-16 13:03:27..

Cms Made Simple

Ayuda para el módulo Ajax Made Simple

What does this module do?
Ajax Made Simple is a developer only module which provides an API to allow module-programmers to easily add Ajax-functionality to the frontend of their modules. Admin-functionality is planned.

How do I use this module?
You should first of all make sure that your module depends on the Ajax Made Simple to make sure it will work on all systems. You could add checks to allow functionality without Ajax Made Simple, but if you want that you probably also know how todo it, so I won't cover that.

In your module-frontend, that is for instanse your Action-function or your action.default.php-file set up the Ajax-requester and provide either the external file or the module-method providing the new content for Ajax to substitute.
You only need 1 or 2 function to set it up and the API goes like this:

function Register Ajax Requester?($modulename,$textid,$divid,$method=,$filename=,$params=array(),$formfields=array(),$refresh=-1) {

The parameters:
$modulename is the name of your module, just use $this->Get Name?()

$textid is a unique id for this requester, allowing you to use several requester in the same module. The modulename is automatically added to the name to there's no need to make it site-wide unique.

$divid is the id of the div inside which you want the new content to be put. Everything within this div is replaced.

$method (optional) is the name of the method in you module that you want to recieve input from Ajax and provide the new content. It could be called anything, but should be in the form: function $My Ajax Output?($vars=array()); $vars is an array containing any info you wanted to pass to the Ajax-provider, like content of form fields or other info (see the $params and $formfields below). $filename (optional) is the name of the file you want to recieve the connection from ajax. Things like formfields or other info is passed in the $_GET array and is base64-encoded! Please use base64_decode()-function for proper values! If the $method parameter is set, $filename is ignored.
Please not that either $method or $filename should be se to something working. And $method has presedence...

$params (optional) is an array containing any info you want to pass on to the ajax-provider. Use the form array(«varname»=>"value")

$formfields (optional) is an array containing the form-input-id's of the fields whose content you want to pass on the the ajax-provider. Fields can optionally be clear after send. Use the form array(«myfieldid»=>"option")
Valid options so far is:

clear – which clears a textfield after ajax has been activated (in a chat input-field for instance, see Chat-module)
radio – which indicates that the wanted field is a set of radio-buttons (for instance in a voting box, see Polls-module, which have to be processed in a special way by ajax. Please not that when referring to radio-buttons the name-of the button tag is used, not the id!

Please not, that for now only 1 option is possible for each formfield. This may change in future versions.

$refresh (optional) allows you to trigger recurring ajax-requests every x'th millisecond. Allow self-updating content. Default is no automatic refresh.

function Get Form On Submit?($modulename,$textid,$pre=,$post=)

The output returned from this function should be put into the form-statement of a form to automatically trigger a Ajax-request when the form is submitted. It can be used as $extra in the module-API function Create Form Start?() or simply echo'ed into your own form before the ending > in the form-tag.

The parameters:
$modulename is the name of your module, just use $this->Get Name?()

$textid is a unique id for this requester, allowing you to use several requester in the same module. The modulename is automatically added to the name to there's no need to make it site-wide unique.

$pre (optional) is any info to be inserted before the Ajax-stuff in the result. $post (optional) is any info to be inserted after the Ajax-stuff in the result.

For a live example of usage, please install the Chat Made Simple-module? and look into the files:

action.default.php (setting up the connections, one using a method the other and external file)
onlinenow.php (the external file-provider)
Ajax Made Simple.method?.php (find the Chat Engine-function? exampling a method-provider)

The Polls-module also uses Ajax MS? in a whole other way, so please have a look there as well.

Good luck! It's actually quite easy when you get the hang of it ;-) And feel free to ask for features or help on getting your module Ajaxified!

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')

Banner Foto.module?.php


From a the session(['ajaxmsgeneratedcode']) i found the javascript function makeBannerFotosbnnrRequest().

I call these functions from a content page, using

<div id="fpbanner">
{cms_module module="Banner Fotos?"}
<span onClick="return makeBannerFotosbnnrRequest();">Klik!

Unfortunately clicking the shufflelink does not replace the content of my div.fpbanner once, it keeps picking a random image (function Maak Foto?)


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);


Does anyone have some experience on this subject?

No hay archivos en esta página. [Enseñar archivos/formulario]
No hay comentarios en esta pagina. [Enseñar comentarios/formulario]