Prototype.js Ajax Object _prototype

Source: Internet
Author: User
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;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.