Manual:Ajax

MediaWiki offers an AJAX interface for use by extensions. AJAX is a term for using JavaScript to load parts of a page on demand. It can be set up as follows:


 * set  in LocalSettings.php. It is set to true by default in MediaWiki 1.17 and above. (Note that if your extension requires Ajax, you should make it check if $wgUseAjax is true, and if not, fail.)
 * MediaWiki 1.16 is shipped with jQuery version 1.3.2, accordingly there is no need to load any separate library for Ajax.

Therefore, Javascript code can use AJAX by invoking function  (or

The function "mw.util.wikiScript" is available since 1.18 onwards.

Non-asynchronous request
The other kind of request sends some data to the server, and waits for the response. This means that the Javascript will be blocked until the server returns some data, or the request fails for some reason.

The following example retrieves the "What links here" list of a template:

( is a standard function that returns an object from its string representation in JSON format.)

Limitations

 * A script cannot retrieve data from a wiki that is hosted on a different domain. (e.g. one cannot retrieve data from http://en.wikipedia.org/wiki/ to http://example.org/wiki/.) This is due to the same origin policy. However, just sending data via GET or POST is possible through some hacks (e.g. submitting a hidden form whose target URL points to the target wiki).