Use the YUI3 IO component to implement ajax

Source: Internet
Author: User

Note: The following statement does not support cross-origin ajax, and does not support cross-origin of subdomains.

/*
* <Div id = "show_info"> </div>
* <Input type = "button" id = "requestButton" value = "Send a POST Request">
*/
YUI (). use ("io", function (Y ){
Var show_info = Y. one ('# show_info ');
Var handleSuccess = function (ioId, o ){
If (o. responseText! = Undefined ){
Var s = "<li> Transaction id:" + ioId + "</li> ";
S + = "<li> HTTP status:" + o. status + "</li> ";
S + = "<li> Status code message:" + o. statusText + "</li> ";
S + = "<li> HTTP headers received ed: <ul>" + o. getAllResponseHeaders () + "</ul> </li> ";
S + = "<li> page response:" + o. responseText + "</li> ";
Show_info.set ("innerHTML", s );
}
}
Var handleFailure = function (ioId, o ){
If (o. responseText! = Undefined ){
Show_info.set ("innerHTML", "handleFailure ");
}
}
Y. on ('IO: success ', handleSuccess );
Y. on ('IO: failure ', handleFailure );
Var cfg = {
Method: "POST ",
Data: "user = fengyue & password = 888 ",
// Data :""
};
Var sUrl = "http://www.alimama.net: 8080/union/aa.htm ";
Function makeRequest (){
Show_info.set ("innerHTML", "Loading data from new request ...");
Var request = Y. io (sUrl, cfg );
}
Y. on ("click", makeRequest, "# requestButton ");
});

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.