JavaScript 跨域请求库 XDomain

XDomain是一个JavaScript CORS跨域请求的库,无需服务器端配置,只需同域下放置proxy.html文件即可使用。它利用XHook获取所有XHR,支持与jQuery和Angular集成,实现跨域XHR无缝工作,无需修改服务器代码,支持FormData访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[url]http://www.oschina.net/p/xdomain[/url]
XDomain 是 JavaScript CORS 跨域请求的一个替代产品,无需任何服务器端的配置。只需要在同域下放置一个 proxy.html 文件即可。该库利用 XHook 来获取所有 XHR,可以无缝的和其他库协同工作。

Features
[color=darkblue]Simple
Library Agnostic
With jQuery $.ajax (and subsequently $.get, $.post)
With Angular $http service
Cross domain XHR just magically works
No need to modify the server code
No need to use IE's silly XDomainRequest Object
Easy XHR access to file servers:
Amazon
Dropbox
Includes XHook and its features
proxy.html files (slaves) may:
White-list domains
White-list paths using regular expressions (e.g. only allow API calls: /^\/api/)
Highly performant
Seamless integration with FormData[/color]


示例代码:
//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);
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值