views:

585

answers:

2

This is an example code from the prototype site.

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' });
  }
});

The data that comes from the ajax request is available at transport.responseText, but what is transport if not only responseText?

+2  A: 

Actually, it's a Ajax.Response object. The linked page lists all the other properties. It's a wrapper around the actual XMLHttpRequest object.

Matthew Flaschen
You're right, it's a simple wrapper with slightly friendlier method names like getHeader instead of getResponseHeader.
karim79
It's not just friendlier names. It adds the JSON stuff, and has different behavior when there are no headers.
Matthew Flaschen
A: 

KJIHU*GYECTDRFWr 7465 iukecd neazdrf3 !!!!!

johan