注意:如下写法不能实现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/879822.html