office excel making a CORS Request as cross domain request

谁说胖子不能爱 提交于 2020-01-12 10:34:09

问题


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

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();

Could someone tell me if it is posible to implement a cors request within excel?

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

});

However when i do a call to :

    $.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);
    },

});

I do get the html page as a result witouth any error's


回答1:


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.



来源:https://stackoverflow.com/questions/38054263/office-excel-making-a-cors-request-as-cross-domain-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!