AJAX Tricks and Prototype
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:\/\/" href="http://prototypejs.org/" title="Linkification: http://prototypejs.org/">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' }); }, parameters: parametersObject, //contains properties+values which will be sent in request. postBody: uploadStuff, //it method=post this is the stuff to upload requestHeaders: object, //define your own headers onComplete: function (t) { //completion does not imply success or failure }, onFailure: function (t) { //we failed. } });
evaled. Ajax.Responders.register or unregister.
Ajax.Responders.register({
onCreate: function() {
Ajax.activeRequestCount++;
},
onComplete: function() {
Ajax.activeRequestCount--;
}
});
//Send contents of id="text" element to server at url=/items // use reply to populate id="items" element, by appending child new Ajax.Updater('items', '/items', { parameters: { text: $F('text') }, insertion: Insertion.Bottom });
new Ajax.PeriodicalUpdater('items', '/items', { method: 'get', frequency: 3, decay: 2 });
10 of 16