XDomain 是 JavaScript CORS 跨域请求的一个替代产品,无需任何服务器端的配置。只需要在同域下放置一个 proxy.html 文件即可。该库利用 XHook 来获取所有 XHR,可以无缝的和其他库协同工作。 Features
示例代码: //do some vanilla XHR
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://xyz.example.com/secret/file.txt');
xhr.onreadystatechange = function(e) {
if(xhr.readyState === 4)
alert(xhr.responseText);
};
xhr.send();
//or if we are using jQuery...
$.get('http://xyz.example.com/secret/file.txt').done(function(data) {
console.log("got result: ", data);
}); |