js跨域

http://www.cnblogs.com/2050/p/3191744.html
评论服务端跨域: CORS
//跨域请求实例
function CORSRequest(method,url,opation,callback) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// 此时即支持CORS的情况
// 检查XMLHttpRequest对象是否有“withCredentials”属性
// “withCredentials”仅存在于XMLHTTPRequest level 2对象里
} else {
// 否则检查是否支持XDomainRequest
// XDomainRequest仅存在于IE中,是IE用于支持CORS请求的方式
xhr = new XDomainRequest();
}
xhr.open(method, url, true);
if(method=="POST"){
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send(opation);
}else{
xhr.send();
}

    xhr.onload = function(){
        callback(xhr.responseText);
         
    }
}
原文地址:https://www.cnblogs.com/sakura-sakura/p/6852058.html