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): enter image description here

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: enter image description here

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

but no avail. error get: enter image description here

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -