Talk:AJAX

From Organic Design wiki

Moving from MooTools to Native Ajax

Currently our Ajax extensions (SimpleForms and Livelets) use the MooTools JavaScript framework. The most commonly used ajax process is to post a form to the server and have the response directed to the innerHTML property of an element having a particular id attribute. The mootools syntax for achieving this functionality is: <js> $('form-id').send({update:$('target-id')}) </js> where form-id specifies the id attribute of the form whose content we want to send to the server, and target-id is the id attribute of the element the servers response should be appear within (usually a div element).

The MediaWiki equivalent of this is a JavaScript function from ajax.js called sajax_do_call, which is used as follows: <js> sajax_request_type = 'POST' // default is GET sajax_do_call('php-function',[data],document.getElementById('target-id')); </js>

It says in MW:Manual:Parameters to index.php regarding action=ajax, that a PHP function in AjaxFunctions.php will be executed. That module contains wfSajaxSearch (search for articles of title similar to a search term) and wfAjaxWatch (watch/unwatch a page). Note that $wgUseAjax must be set to true and the only callable functions are those in the array $wgAjaxExportList (which is also modified by the variables $wgAjaxSearch and $wgAjaxWatch). In addition to action=ajax, there is rs (the function name, e.g. rs=wfSajaxSearch), rsargs[] (an array of arguments to the function (e.g., rsargs[]=abcd passes the abcd string to the function). There is a JavaScript function for calling this action in ajax.js.