使用YUI3 IO组件实现ajax

前端之家收集整理的这篇文章主要介绍了使用YUI3 IO组件实现ajax前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
注意:如下写法不能实现ajax跨域,连子域跨域都不行。

/*
*<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: <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");
});

猜你在找的Ajax相关文章