办公室擅长制作CORS请求作为跨域请求 [英] office excel making a CORS Request as cross domain request
问题描述
我正在尝试从我的excel addin,
做出一个跨域请求,如下所示: http://dev.office.com/docs/add-ins/develop/addressing-same-origin-policy-limitations
I am trying to make a cross domain request from my excel addin, as sugested by here : http://dev.office.com/docs/add-ins/develop/addressing-same-origin-policy-limitations
我正在尝试执行cors请求。
但是,无论何时我尝试打开我的请求,我得到一个被拒绝的错误。
i am trying to implement a cors request. However whenever i try to open my request i get an acces denied error.
我使用这里的代码尝试打开一个连接,但在这里我已经得到错误
the code i use herefor try's to open a connection however here i already get the error
var xhr = new XMLHttpRequest();
xhr.open('GET', 'url'); //this line gives an acces denied error.
xhr.onload = function(e) {
}
xhr.send();
有人可以告诉我,是否可以在excel中实现cors请求?
Could someone tell me if it is posible to implement a cors request within excel?
具有ajax的代码还给出了错误对象
The code with ajax gives also an error object
$.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页面,因为任何错误的
I do get the html page as a result witouth any error's
推荐答案
HTML5 Rocks 有一些关于在客户端进行CORS请求的好提示。在服务器上完成了很多CORS设置,但假定服务器设置为允许您的请求,则可能需要在 xhr.withCredentials = true;
之前包含您的打开
呼叫。
HTML5 Rocks has some good tips on making CORS requests on the client-side. A lot of CORS setup is done on the server, but assuming that the server is set up to allow your request, you might just need to include xhr.withCredentials = true;
before your open
call.
这篇关于办公室擅长制作CORS请求作为跨域请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!