1.js可跨域
convertServer={
requestByScript: function(scriptId, dataHref, callback, charset, retry) {
var isReady = false;
if (callback) {
if (typeof (callback) == "string") {
charset = callback;
callback = null;
}
}
var head = document.getElementsByTagName("head")[0];
var objScript = document.getElementById(scriptId);
if (objScript && !document.all) {
objScript.src = "";
objScript.parentNode.removeChild(objScript);
objScript = null;
}
if (objScript != null) {
if (dataHref.indexOf("?") == -1) dataHref += "?";
dataHref += "&" + Math.random();
objScript.src = dataHref;
var dataScript = objScript;
} else {
var dataScript = document.createElement("script");
dataScript.id = scriptId;
if (charset) {
dataScript.charset = charset;
} else {
dataScript.charset = "GB2312";
}
dataScript.src = dataHref;
dataScript.defer = true;
dataScript.type = "text/javascript";
head.appendChild(dataScript);
}
if (document.all) {
dataScript.onreadystatechange = function() {
if (dataScript.readyState == "loaded" || dataScript.readyState == "complete") {
isReady = true;
if (callback) callback();
}
}
} else {
dataScript.onload = function() {
isReady = true;
if (callback) callback();
}
}
if (retry) {
setTimeout(function() {
if (retry.times > 0 && !isReady) {
retry.times--;
if (dataHref.indexOf("?") == -1) dataHref += "?";
dataHref += "&" + Math.random();
convertServer.requestByScript(scriptId, dataHref, callback, charset, retry);
}
}, retry.timeout);
}
},
requestData:function(url,callBack)
{
var scriptId="jsReuest"+ Math.random();
convertServer.requestByScript(scriptId, url, callBack)
}
}
2. jQuery.ajax(options),不能跨域