jquery - Calling Web Service From Outlook Mail Add-In -
i'm bit stuck on 1 problem have outlook mail add-in. using office 365 developer account, mail add-in show (online, in browser):
i want call rest web service when click button.
first, let me post 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> <!-- enable offline debugging using local reference 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 , footer tags not supported--> <div id="content-main"> click button test create method <br /> <label id="lblmessage">message appear here</label> <button id="btntest" type="button">perform test create</button> <!--<iframe id="my_api_iframe"></iframe>--> </div> </body> </html>
this html see in first screenshot.
the office.initialize js code, want see:
office.initialize = function (reason) { //_mailbox = office.context.mailbox; ////request identity token 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(); }); }); };
i have tried different ways this. when button clicked, calls specified function, here's few ways have tried:
function getlist() { jquery.support.cors = true; $.ajax({ type: "get", url: [url webmethod], success: function (data, textstatus) { $('#lblmessage').text("success"); }, error: function (xhr, textstatus, errorthrown) { $('#lblmessage').text("error: " + errorthrown + " statuscode: " + textstatus + " xhr: " + xhr.readystate); } }); }
but when button clicked , call function, error get:
the 2nd function tried:
function getlist2() { $.ajax({ type: "get", url: [url webmethod], xhr: function () { return new ($('#my_api_iframe')[0].contentwindow.xmlhttprequest)(); }, success: function (html) { // format , output result $('#lblmessage').text(html); }, error: function (xhr, textstatus, errorthrown) { // format , output result $('#lblmessage').text(errorthrown); } }); }
last function tried:
function gettokencallback(asyncresult) { var token = asyncresult.value; // create web service call , pass token part of call. _xhr = new xmlhttprequest(); _xhr.open("get", [url 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)); }
but same "access denied" error before, @ point _xhr.open().
can maybe me in right direction these rest services called? return data in xml format, that's why used contenttype of "application/xml".
any appreciated, if it's different way i'm trying :).
Comments
Post a Comment