Home  >  Article  >  Web Front-end  >  Ajax object_prototype for prototype.js

Ajax object_prototype for prototype.js

WBOY
WBOYOriginal
2016-05-16 19:25:58979browse

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

Copy code The code is 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 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.
The actual code used in the example
Copy the code The code is as follows:

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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn