I think the Ajax object in Prototype.js must have attracted a lot of people, and a lot of the classes that encapsulate the Ajax logic are a great help to us beginners using AJAX.
Here is a specific example of my use to explain: effect look here
1. Ajax.request
You can create it like this
Copy Code code as follows:
var url = ' Http://yoursever/your/your ';
var pars = ' id=xxx ';
var myajax = new Ajax.request (
Url
{method: ' Get ', Parameters:pars, oncomplete:yourfunction}
);
Parameters indicate the parameters you want to pass, such as Id=xxx.
The phases of XMLHttpRequest during HTTP requests are divided into: Loading, Loaded, Interactive, Complete.
The Ajax.request object can call your custom method at any stage, such as Onxxxxxxx:yourfunction, the oncomplete we mentioned above, is the most commonly used.
The actual code used in the example
Copy Code code as follows:
Function sends (id)
{
c = $ (' content ');
o = $ (' old-content ');
c.innerHTML = "<div id= ' loading ' > Loaded in ...</div>";
o.innerHTML = c.innerHTML;
c.style.display = ' None ';
o.style.display = ' block ';
var myajax = new ajax.request (' Content_ ' + id + '. html ', {method: ' get ', oncomplete:updates});
}
Function updates (response)
{
new effect.fade ($ (' old-content ') );
new effect.appear ($ (' content '));
$ (' content ') .innerhtml = response.responsetext;
}