Manual:Ajax

MediaWiki offers an AJAX interface for use by extensions. It can be used as follows:


 * set  in LocalSettings.php (if your extension requires Ajax, make it check if $wgUseAjax is true, and if not, fail)
 * in your extension setup code, register a function for use via Ajax:  The function's name may contain :: to reference a function defined inside a class.
 * The handler function you register will be called with the list of parameters passed to  (or , respectively), see below.
 * The handler function you register can either return a string (which should be in the format the JavaScript code expects, typically HTML, XML, JSON, or a single textual value,) or, for more control over the HTTP headers of the response (especially with respect to the reported content type, cache control, etc) the function should return an instance of AjaxResponse.
 * in your extension's JavaScript code, you can now call your PHP function:  a and b would be the two parameters that myExtensionFunction expects (you can have any number of parameters), and target defines where the response data from the PHP Ajax handler should be sent.
 * If target is a JavaScript function, it will called with the XMLHttpRequest object as parameter.
 * If target is an input element, its value will be set to the resultText.
 * If target is any other kind of element, its innerHTML will be set to the resultText
 * sajax_do_call uses the  mode to call index.php. It passes the arguments using two additional parameters:   (the function name, e.g.,  ), and   (for parameters, possibly repeated, e.g.  ).

AjaxResponse
The AjaxResponse response class is defined in AjaxResponse.php. It represents the response sent by an Ajax handler function, and controls the actual response text as well as HTTP headers indicating the content type, cache control, etc.

Detailed documentation pending, see the source for now.


 * source code in SVN
 * class documentation (doxygen)

Examples
Some extensions that use MediaWiki's Ajax interface can be found in Category:Ajax extensions.