设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

XDomain—JavaScript跨域请求库

2014-7-14 15:23| 发布者: joejoe0332| 查看: 237217| 评论: 2|原作者: oschina|来自: oschina

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

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


Features

  • Simple

  • Library Agnostic

    • With jQuery  $.ajax (and subsequently $.get, $.post)

    • With Angular $http service

  • Cross domain XHR just magically works

  • Easy XHR access to file servers:

  • 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

示例代码:

//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);
});

酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部