I think the ajax objects in prototype. js will certainly attract a lot of people and a large number of encapsulated ajax logic classes will be of great help to our beginners who use ajax.
Here is an example of my use:
1. Ajax. Request
You can create it like this
Copy codeThe Code is as follows:
Var url = 'HTTP: // yoursever/your ';
Var pars = 'id = XXX ';
Var myAjax = new Ajax. Request (
Url,
{Method: 'get', parameters: pars, onComplete: yourfunction}
);
Parameters indicates the parameters you want to pass, such as id = xxx.
XMLHttpRequest is divided into Loading, Loaded, Interactive, and Complete in the HTTP request.
Ajax. Request objects can call your custom methods at any stage, in the form of onxxxxxxx: yourfunction. For example, onComplete mentioned above is the most commonly used method.
Code actually used in the example
Copy codeThe Code is as follows:
Function sends (id)
{
C = $ ('content ');
O = $ ('old-content ');
C. innerHTML = "<div id = 'loading'> loading... </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;
}