2009-06-24 7 views
1

これはプロトタイプサイトのサンプルコードです。プロトタイプのAjaxリクエスト - responseTextだけでなく、トランスポートとは何ですか?

var url = '/proxy?url=' + encodeURIComponent('http://www.google.com/search?q=Prototype'); 
// notice the use of a proxy to circumvent the Same Origin Policy. 

new Ajax.Request(url, { 
    method: 'get', 
    onSuccess: function(transport) { 
    var notice = $('notice'); 
    if (transport.responseText.match(/href="http:\/\/prototypejs.org/)) 
     notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' }); 
    else 
     notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' }); 
    } 
}); 

ajaxリクエストから得られるデータは、transport.responseTextで入手できますが、responseTextだけでなく、トランスポートとは何ですか?

答えて

2

実際にはAjax.Responseオブジェクトです。リンクされたページには、他のすべてのプロパティが一覧表示されます。これは、実際のXMLHttpRequestオブジェクトのラッパーです。

+0

あなたはそうです、それはgetResponseHeaderの代わりにgetHeaderのような少し面白いメソッド名を持つ単純なラッパーです。 – karim79

+0

これは単なる友好的な名前ではありません。これは、JSONのものを追加し、ヘッダーがない場合の動作が異なります。 –

関連する問題