1

I am trying to build an Excel/Word task pane add-in that should show content from our site. The content/data is passed in XML format.

What I have tried to do is the following:

Office.initialize = function (reason) {
    $(document).ready(function () {
        app.initialize();

        $.support.cors = true;

        var data = '';

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: 'http://addons.mysite.com/excel-taskpane-data.php',
            data: data,
            dataType: "json",
            success: onQuerySuccess,
            error: onQueryError
        });

        function onQuerySuccess(res, statusText) {
            console.log('success!!' + res.statusText);
        }
        function onQueryError(res, statusText){
            console.log('failed!!' + res.statusText);
        }

  });

};

As you can understand from the code above I was just checking if connection could be made to the external source, but I am getting "Access Denied" in the console.

I am not really sure how should I request data from an external source and whether it is possible at all?

Please help

AlexB
  • 2,164
  • 6
  • 27
  • 61
  • Are you sure all this is about office addins and not about Apps for office? – Alex Butenko Feb 08 '16 at 21:35
  • @AlexButenko Apps for Office have been renamed as Office add-ins. Now this terminology refers to both technologies, which is extremely error prone – Benoit Patra Feb 08 '16 at 21:54
  • @BenoitPatra oh, thanks, I was absolutely sure that office-addins tag is about .net addins. Maybe we need to edit the tag descriptions then. – Alex Butenko Feb 08 '16 at 21:57
  • @AlexButenko for outlook add-ins a tag outlook-web-addins has been created but not for all office-addins. – Benoit Patra Feb 09 '16 at 02:31

2 Answers2

1

You mentioned 'external' so I bet http://addons.mysite.com/ is not the domain that serves your web add-in. To make it work you have to check several things.

  1. Serving with Https. As written by Michael make sure you use https. Mixed content (mixing of http and https) is blocked by most server and Office web add-ins can only be served with https.
  2. Make sur your PHP web api supports CORS. I am no PHP expert so here is a small link
  3. Try to specify https://addons.mysite.com as AppDomain The sandboxed iFrame allow only request and navigation on the same domain (the one that you use to serve you web-addin). But you can specify some exceptions see here. It works with navigation and I am not sure it works with XHR...
  4. If step 3 did not work try to use JSON/P techniques as described here JSON/P with Office add-ins
Benoit Patra
  • 4,355
  • 5
  • 30
  • 53
  • I have followed all steps, but still no results in my Excel Add-on. I have actually changed the script slightly and all works just fine in the browser, but when I use the same js in my add-on, nothing happens. – AlexB Feb 14 '16 at 16:46
  • found a problem, for some reason application cannot use the jquery in the Scripts folder so I have to add it to App folder and now wverything works like magic. – AlexB Feb 14 '16 at 17:25
0

Yes, you can make Ajax HTTP requests from Office web add-ins such as your Excel/Word task pane. They work exactly the same as they would on a normal web page, except we have an additional requirement of using "https" rather than "http" to access the endpoint.

I can't identify the cause of your specific issue without information about the actual endpoint you're calling. Start by just trying your code on a normal web page and access it normally with a web browser. Once you have that working, then point an add-in to the page. That should fix your issue, but if you still have a problem where the exact same code is working in a normal browser and failing in an add-in, let us know.

Michael Saunders
  • 2,662
  • 1
  • 12
  • 21