logo

WikiJuanan: AjaxMadeSimple ...

Inicio | Indice De Paginas | Ultimas Modificaciones | Ultimos Commentarios | Usuarios | Registrarse | Conectar:  Contraseña:  

Cms Made Simple


Ayuda para el módulo Ajax Made Simple


¿Qué hace este módulo?
Ajax Made Simple es un módulo sólo para desarrolladores que proporcionan una API para añadir de manera sencilla funcionalidad Ajax a sus propios módulos en la interfaz de usuario. Está planeado su uso futuro en la interfaz administrativa.


¿Cómo se usa este módulo?
Lo primero que debes hacer es asegurarte de que tu módulo depende de Ajax Made Simple para que pueda funcionar en cualquier sistema. Puedes añadir comprobaciones para hacer que el módulo puede también trabajar sin Ajax Made Simple, pero si quieres eso probablemente ya sabes cómo hacerlo, así que no lo contemplaremos aquí.


En el frontend o interfaz de tu módulo, por ejemplo tu función “Action” o tu fichero “action.default.php-file” configura el Ajax-requester y proporcionale bien el fichero externo o el método del modulo que proporciona el nuevo contenido para que Ajax lo substituya. Sólo necesitas configurar un par de funciones y la API es algo así como:


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



action.default.php



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


I call these functions from a content page, using
Code:


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


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


Code:


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

}


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]