Reputation: 2484
I was coding an app for Office, where i planned to use AJAX to load contents dynamically from a external website to the office app. I have the following JS function. When the execution reaches to a.open()
function, it shows an error:
Unhandled exception at line 31, column 21 in https://localhost:44304/App/Home/Home.js
0x80070005 - JavaScript runtime error: Access is denied.
-
function getDataFromSelection() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
var a = new XMLHttpRequest();
a.onreadystatechange = function () {
if (a.readyState == 4 && a.status == 200) {
var jSONstr = a.responseText;
var obj = jQuery.parseJSON(jSONstr);
showSearch(obj);
}
};
a.open("GET", "http://some.external.site/page.php?query=" + result.value, true); //This has got the error
a.send();
}
else {
app.showNotification('Damn!:', result.error.message);
}
}
);
}
Is AJAX not supported in Office Apps? How can i do the exact thing the other (working) way?
PS: I am using Visual Studio 2012 On Win8
Upvotes: 0
Views: 963
Reputation: 2412
The error is triggered because you tried to make a cross site request via ajax.
A browser rarely allows this kind of requests, so you should find a workaround making a JSONP request or an ajax request to a server-side script that handles the server-to-server communication.
Upvotes: 1