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). 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 callback is a JavaScript function that takes an XMLHttpRequest as a parameter - this is used as the standard Ajax callback, that is, that function is called whenever the request's state changes.
 * 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 send 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