办公室excel做一个CORS请求作为跨域请求
我正在尝试从我的excel插件发出一个跨域请求,正如这里所要求的: http : //dev.office.com/docs/add-ins/develop/addressing-same-origin-policy-limitations
我正在尝试实施Cors请求。 但是,每当我尝试打开我的请求,我得到一个访问被拒绝的错误。
我在这里使用的代码尝试打开一个连接,但是在这里我已经得到了错误
var xhr = new XMLHttpRequest(); xhr.open('GET', 'url'); //this line gives an acces denied error. xhr.onload = function(e) { } xhr.send();
有人可以告诉我,是否可以在Excel中实现Cors请求?
带有ajax的代码也给出了一个错误对象
$.ajax({ type: 'GET', url: 'remoteurl', cache: true, }, success: function (result) { functionAfterLoad(JSON.parse(JSON.stringify(eval("(" +result + ")")))); }, error: function(result) { console.error('Error while retrieving funnel HTML', result); }, });
但是,当我打电话给:
$.ajax({ type: 'GET', url: window.location.href , cache: true, }, success: function (result) { functionAfterLoad(JSON.parse(JSON.stringify(eval("(" +result + ")")))); }, error: function(result) { console.error('Error while retrieving funnel HTML', result); }, });
因为有任何错误,我确实得到了html页面
HTML5 Rocks在客户端提供CORS请求方面有一些很好的技巧。 很多CORS设置都是在服务器上完成的,但是假设服务器设置为允许你的请求,你可能只需要包含xhr.withCredentials = true;
在你open
电话之前。