| クラス | 説明 |
|---|---|
| Ajax.Request | Ajaxリクエスト |
| Ajax.Response | Ajaxリクエストのレスポンス |
| Ajax.Updater | Ajaxリクエストを行い、そのレスポンスで指定要素を書き換える |
| Ajax.PeriodicalUpdater |
new Ajax.Request( url [ , options ] )
Ajax.Request()は内部的にはXmlHttpRequest.open()を呼び出すだけのため、リクエストできるURLは同一起源ポリシーの制約を受けます。なおjQueryのAjaxは、この制約を回避する機能を提供しています。
var params = { a:100, b:'foo' };
new Ajax.Request( 'index.php',
{
method: 'get',
parameters: params,
onSuccess: function( response )
{
console.debug( response );
}
} );
| プロパティ | 型 | 説明 | 既定値 |
|---|---|---|---|
| asynchronous | Boolean | Determines whether XMLHttpRequest is used asynchronously or not. Synchronous usage is strongly discouraged — it halts all script execution for the duration of the request and blocks the browser UI. | true |
| contentType | String | The Content-type header for your request. Change this header if you want to send data in another format (like XML). | application/x-www-form-urlencoded |
| encoding | String | The encoding for the contents of your request. It is best left as-is, but should weird encoding issues arise, you may have to tweak this. | UTF-8 |
| method | String | The HTTP method to use for the request. The other common possibility is get. Abiding by Rails conventions, Prototype also reacts to other HTTP verbs (such as put and delete) by submitting via post and adding a extra _method parameter with the originally-requested method. | post |
| parameters | String |
リクエストのパラメータ。GETメソッドではURLに、他のメソッドではリクエスト ボディにエンコードされる。 これはURLエンコードされた文字列、Hashオブジェクト、またはオブジェクトリテラル形式のオブジェクトのいずれかとする。
|
|
| postBody | String | POSTメソッドのリクエスト ボディの内容。これを指定しない場合は、parametersプロパティが代わりに使用される。 | |
| requestHeaders | Object | A set of key-value pairs, with properties representing header names. | |
| evalJS | Boolean | String | Automatically evals the content of Ajax.Response#responseText and populates Ajax.Response#responseJSON with it if the Content-type returned by the server is set to application/json. If the request doesn't obey same-origin policy, the content is sanitized before evaluation. If you need to force evalutation, pass 'force'. To prevent it altogether, pass false. | true |
| sanitizeJSON | Boolean | Sanitizes the contents of Ajax.Response#responseText before evaluating it. | false for same-origin requests, true otherwise |
| メソッド | 説明 |
|---|---|
| onCreate | Triggered when the Ajax.Request object is initialized. This is after the parameters and the URL have been processed, but before opening the connection via the XHR (XMLHttpRequest) object. |
| onUninitialized ※1 | Invoked just after the XHR object is created. |
| onLoading ※1 | Triggered when the underlying XHR object is being setup, and its connection opened. |
| onLoaded ※1 | Triggered once the underlying XHR object is setup, the connection is open, and it is ready to send its actual request. |
| onInteractive ※1 | Triggered whenever the requester receives a part of the response (but not the final part), should it be sent in several packets. |
| onSuccess | Invoked when a request completes and its status code is undefined or belongs in the 2xy family. This is skipped if a code-specific callback is defined (e.g., on200), and happens before onComplete. |
| onFailure | Invoked when a request completes and its status code exists but is not in the 2xy family. This is skipped if a code-specific callback is defined (e.g. on403), and happens before onComplete. |
| onXYZ |
Invoked just after the response is complete if the status code is the exact code used in the callback name. Prevents execution of onSuccess and onFailure. Happens before onComplete. (with XYZ representing any HTTP status code) |
| onException | Triggered whenever an XHR error arises. Has a custom signature: the first argument is the requester (i.e. an Ajax.Request instance), and the second is the exception object. |
| onComplete | Triggered at the very end of a request's life-cycle, after the request completes, status-specific callbacks are called, and possible automatic behaviors are processed. Guaranteed to run regardless of what happened during the request. |
| readyState | メソッド | XHRでの名称 |
|---|---|---|
| 0 | onUninitialized | Uninitialized |
| 1 | onLoading | Open |
| 2 | onLoaded | Sent |
| 3 | onInteractive | Receiving |
| 4 | onComplete | Loaded |
| 分類 | プロパティ | 説明 |
|---|---|---|
| headerJSON | ||
| readyState | リクエストの状態を表す数値
それぞれの状態に変化するときに、状態名の先頭に「on」を付けたコールバックを呼び出す |
|
| リクエスト | request | リクエストに使用した Ajax.RequestまたはAjax.Updaterオブジェクト |
| レスポンス | responseJSON | レスポンスのJSONボディ |
| responseText | レスポンスのテキスト ボディ | |
| responseXML | レスポンスのXMLボディ | |
| ステータス | status | HTTPステータス コード |
| statusText | HTTPステータス テキスト | |
| transport | XmlHttpRequestオブジェクト |
| 分類 | メソッド | 説明 |
|---|---|---|
| Header | getHeader | |
| getAllHeaders | ||
| ResponseHeader | getResponseHeader | |
| getAllResponseHeaders |