软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > Web前端 > Ajax/JavaScript > 使用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");
});
    相关阅读
    网友评论