office excel making a CORS Request as cross domain

2019-04-01 23:58发布

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条回答
祖国的老花朵
2楼-- · 2019-04-02 00:07

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.

查看更多
登录 后发表回答