I think the ajax object in prototype.js must have attracted a lot of people. A large number of classes that encapsulate ajax logic are of great help to us beginners using ajax.
The following is explained with a specific example of my use: see the effect here
1. Ajax.Request
You can create it like this
parameters means you want Passed parameters, such as id=xxx.
The stages of XMLHttpRequest during the HTTP request are divided into: Loading, Loaded, Interactive, Complete.
The Ajax.Request object can call your customized method at any stage, in the form of onxxxxxxx:yourfunction, such as onComplete we mentioned above, which is the most commonly used.
function sends( id)
{
c = $('content');
o = $('old-content');
c.innerHTML = "
Loading...
";
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;
}