Search

Ajax.Response
Ajax.Response

unknown

new Ajax.activeRequestCount;
Ajax.Responseオブジェクトのプロパティ
プロパティタイプ説明
statusNumberThe HTTP status code sent by the server.
statusTextStringThe HTTP status text sent by the server.
readyStateNumberThe request’s current state. 0 corresponds to 'Uninitialized', 1 to 'Loading', 2 to 'Loaded', 3 to 'Interactive' and 4 to 'Complete'.
responseTextStringThe text body of the response.
responseXMLdocument Object or nullThe XML body of the response if the content-type of the request is set to application/xml. null otherwise.
responseJSONObject, Array or nullThe JSON body of the response if the content-type of the request is set to application/json. null otherwise.
headerJSONObject, Array or nullAuto-evaluated content of the X-JSON header if present. null otherwise. This is useful to transfer small amounts of data.
requestObjectThe request object itself (an instance of Ajax.Request or Ajax.Updater).
transportObjectThe native xmlHttpRequest object itself.
Ajax.Responseオブジェクトのメソッド
メソッドタイプ説明
getHeader(name)String or nullReturns the value of the requested header if present. null otherwise. Does not throw errors on undefined headers like it’s native counterpart does.
getAllHeaders()String or nullReturns a string containing all headers separated by a line break. Does not throw errors if no headers are present like it’s native counterpart does.
getResponseHeader(name)StringReturns the value of the requested header if present. Throws an error otherwise. This is just a wrapper around the xmlHttpRequest object’s native method. Prefer it’s shorter counterpart getHeader.
getAllResponseHeaders()StringReturns a string containing all headers separated by a line break. Throws an error otherwise. This is just a wrapper around the xmlHttpRequest object’s native method. Prefer it’s shorter counterpart getAllHeaders.

非同期通信のリクエスト数を取得
activeRequestCount

unknown

new Ajax.activeRequestCount;
サンプルを見る
<p>
    <input type="button" onclick="fUpdater('include/ajax/xmltodom/ranking.xml')" value="XMLデータ読込" />
    <input type="button" onclick="fUpdater('index.rdf')" value="RDFデータ読込" />
    <input type="button" onclick="fUpdater('index.html')" value="HTMLデータ読込" />
</p>
リクエスト数:<input type="text" id="res_requestcount" size="3" />&nbsp;回
<p>
    <textarea id="res_text" style="width:90%; height:10em;"></textarea>
</p>

<script type="text/javascript">
function fUpdater(url){
    new Ajax.Updater(
        { success:"res_text"},
        url,
        {
              method: 'get',
              onFailure:function(httpObj){
                  $("res_text").value="エラー発生";
              }
          }
    );
    $("res_requestcount").value=Ajax.activeRequestCount;
}
</script>

options

unknown

共通のオプション
optionデフォルト値説明
asynchronous TRUE 非同期通信フラグ (true : 非同期, false : 非同期)
contentType 'application/x-www-form-urlencoded' リクエストヘッダ。
encoding 'UTF-8' 文字エンコード
method 'post' メソッド (get, post, put, propfind)
parameters '' パラメータ
postBody None メソッドが'post'の場合の送信データ
requestHeaders See text HTTPヘッダーの配列
evalJS true
evalJSON true
sanitizeJSON ローカルリクエストの場合はFALSE、それ以外の場合はTRUE
共通のコールバック関数
Callback説明
onCreate 非同期通信オブジェクトが作成された時に呼び出される
onComplete 通信完了時に呼び出される
onException 読込時に何らかのエラーが発生した時に呼び出される
onFailure 通信失敗時に呼び出される
onInteractive
onLoaded 読込終了時に呼び出される
onLoading 読込開始時に呼び出される
onSuccess 読込成功時に呼び出される
onUninitialized
onXYZ

非同期通信で読み込んだデータをページに表示
Updater

unknown

new Ajax.Updater(container, url[, options]);
サンプルを見る
<p>
    <input type="button" onclick="fUpdater('include/ajax/xmltodom/ranking.xml')" value="XMLデータ読込" />
    <input type="button" onclick="fUpdater('index.rdf')" value="RDFデータ読込" />
    <input type="button" onclick="fUpdater('index.html')" value="HTMLデータ読込" />
</p>

<p>
    ▼文字列として取得:<br>
    <textarea id="res_text" style="width:90%; height:10em;"></textarea>
</p>

<script type="text/javascript">
function fUpdater(url){
    new Ajax.Updater(
        { success:"res_text"},
        url,
        {
              method: 'get',
              onFailure:function(httpObj){
                  $("res_text").value="エラー発生";
              }
          }
    );
}
</script>

非同期通信
Request

unknown

new Ajax.Request(url[, options]);
サンプルを見る
<p>
    <input type="button" onclick="fRequest('include/ajax/xmltodom/ranking.xml')" value="XMLデータ読込" />
    <input type="button" onclick="fRequest('index.rdf')" value="RDFデータ読込" />
    <input type="button" onclick="fRequest('index.html')" value="HTMLデータ読込" />
</p>

<p>
    ▼文字列として取得:<br>
    <textarea id="res_text" style="width:90%; height:10em;"></textarea>
</p>
<p>
    ▼XMLとして取得:<br>
    <textarea id="res_xml" style="width:90%; height:10em;"></textarea>
</p>

<script type="text/javascript">
function fRequest(url){
    new Ajax.Request(url,
        {
              method: 'get',
              onSuccess:function(httpObj)
              {
                  $("res_text").value=httpObj.responseText;
                  $("res_xml").value=httpObj.responseXML;
              },
              onFailure:function(httpObj)
              {
                  alert("エラー発生");
              }
          }
    );
}
</script>

関連コンテンツ

Q. このサイトの情報はお役に立ちましたでしょうか?

投票する 投票結果を見る

管理人に【web拍手】を送るweb拍手(1行メッセージも送れます♪)

pagetop

polarized women