[英]Calling Web Service From Outlook Mail Add-In
我對Outlook Mail加載項遇到的這個問題有些困惑。 我使用的是Office 365開發人員帳戶,郵件加載項將顯示在其中(在線,在瀏覽器中):
單擊按鈕時,我想調用REST Web服務。
首先,讓我發布我的HTML:
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>
<!-- To enable offline debugging using a local reference to Office.js, use: -->
<!-- <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script> -->
<!-- <script src="../../Scripts/Office/1.1/office.js" type="text/javascript"></script> -->
<link href="../App.css" rel="stylesheet" type="text/css" />
<script src="../App.js" type="text/javascript"></script>
<link href="Home.css" rel="stylesheet" type="text/css" />
<script src="Home.js" type="text/javascript"></script>
</head>
<body>
<!--Header and Footer tags not supported-->
<div id="content-main">
Click this button to test the create method
<br />
<label id="lblMessage">Message will appear here</label>
<button id="btnTest" type="button">Perform Test Create</button>
<!--<iframe id="my_api_iframe"></iframe>-->
</div>
</body>
</html>
這是我們在第一個屏幕截圖中看到的HTML。
Office.initialize JS代碼,供那些想看的人參考:
Office.initialize = function (reason) {
//_mailbox = Office.context.mailbox;
////Request identity token from Exchange Server.
//_mailbox.getUserIdentityTokenAsync(getTokenCallback);
$(document).ready(function () {
app.initialize();
//SET Variables
loggedInUserDisplayName = Office.context.mailbox.userProfile.displayName;
loggedInUserEmailAddress = Office.context.mailbox.userProfile.emailAddress;
var conversationID = Office.context.mailbox.item.conversationId;
var internetMessageID = Office.context.mailbox.item.internetMessageId;
var itemID = Office.context.mailbox.item.itemId;
//$('#lblMessage').text("ConversationID:" + convoID + " InternetMessageID:" + intMessID + " ItemID:" + itemID);
$("#btnTest").click(function () {
GetList();
//GetList2();
});
});
};
我嘗試了不同的方法來做到這一點。 單擊按鈕后,它將調用指定的函數,這是我嘗試的幾種方法:
function GetList() {
jQuery.support.cors = true;
$.ajax({
type: "GET",
url: [URL to WebMethod],
success: function (data, textStatus) {
$('#lblMessage').text("Success");
},
error: function (xhr, textStatus, errorThrown) {
$('#lblMessage').text("Error: " + errorThrown + " StatusCode: " + textStatus + " XHR: " + xhr.readyState);
}
});
}
我嘗試的第二個功能:
function GetList2() {
$.ajax({
type: "GET",
url: [URL to WebMethod], xhr: function () {
return new ($('#my_api_iframe')[0].contentWindow.XMLHttpRequest)();
}, success: function (html) {
// format and output result
$('#lblMessage').text(html);
}, error: function (xhr, textStatus, errorThrown) {
// format and output result
$('#lblMessage').text(errorThrown);
}
});
}
我嘗試的最后一個功能:
function getTokenCallback(asyncResult) {
var token = asyncResult.value;
// Create a web service call and pass the token as part of the call.
_xhr = new XMLHttpRequest();
_xhr.open("GET", [URL to WebService]);
_xhr.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
_xhr.onreadystatechange = readyStateChange;
var request = new Object();
request.token = token;
request.
request.phoneNumbers = _om.get_item().getEntities().phoneNumbers;
_xhr.send(JSON.stringify(request));
}
但是在執行_xhr.open()時,出現了與以前相同的“拒絕訪問”錯誤。
誰能在正確的方向上幫助我,讓這些REST服務得到調用? 它們都以XML格式返回數據,這就是為什么我使用“ application / xml”的ContentType的原因。
任何幫助將不勝感激,即使它與我正在嘗試的方法完全不同:)。
您的iframe
HTML元素已被注釋掉。 嘗試取消注釋。 至少這就是為什么GetList2()失敗的原因。
所以改變
<!--<iframe id="my_api_iframe"></iframe>-->
至
<iframe id="my_api_iframe"></iframe>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.