js 跨域请求,使用 jsonp
[code]//跨域请求
function domain_request(param) {
jsonp_str = 'jsonp_' + new Date().getTime();
eval(jsonp_str + ' = ' + param.success + ';');
param.url += '?callback=' + jsonp_str;
for(var i in param.data) {
param.url += '&' + i + '=' + param.data[i];
}
doc_head = document.getElementsByTagName("head")[0];
doc_js = document.createElement("script");
doc_js.src = param.url;
doc_js.onload = doc_js.onreadystatechange = function(){
if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete"){
//清除JS
doc_head.removeChild(doc_js);
}
}
doc_head.appendChild(doc_js);
}
domain_request({
url:'http://abc.com',
data:{key:'abc'},
success:function() {
alert('ok');
}
});[/code]