Manual:Ajax/ja

MediaWikiはエクステンションの使用のためにAJAXインターフェイスを提供します. AJAX is a term for using JavaScript to load parts of a page on demand. It can be set up as follows:


 * 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.

同期リクエスト
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, it is difficult for a script on an external site to retrieve data from a wiki that is hosted on a different domain &mdash; for example, one cannot directly retrieve data from  to. Newer browsers support an explicit instruction to permit this access via cross-origin resource sharing but this will only work with servers that are configured to issue the appropriate headers, and the user must be using a recent browser that recognises it. Developers with concerns about legacy browsers can't rely on CORS yet.

It is possible to circumvent the Same-Origin policy using JSONP instead of plain JSON / XML which will work in older browsers down to Internet Explorer 6. [This may require jQuery 1.5 or newer]

Deprecated functionality
Sajax is an ancient Ajax library that (as of September 2012) is still part of core code and is used by some extensions. Don't use it, use  instead.

Some extensions, whether using Sajax or not, make Ajax calls through the obsolete AjaxDispatcher by invoking. They should instead make MediaWiki API requests to API modules.

関連項目

 * Category:Ajax extensions - Extensions that use the Ajax interface of MediaWiki.

外部リンク
XMLHttpRequestに関する一般的な情報:
 * MediaWiki's Resource Loader module
 * jQuery Ajax API
 * http://www.w3.org/TR/XMLHttpRequest/
 * XMLHttpRequest
 * http://www.w3schools.com/dom/dom_http.asp