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 Javascript standard function that returns an object from its string representation in JSON format.)

Limitations
Due to the same origin policy, a script cannot retrieve data from a wiki that is hosted on a different domain - for example, one cannot retrieve data from  to   - unless the target server allows the sender domain through cross-origin resource sharing.

There are a few hacks that allow one to circumvent this restriction when just sending data (as opposed to retrieving). An example is submitting a hidden form whose target URL points to the target wiki.