Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send POST AJAX request from Office Add-In

I'm trying to send POST Ajax request for third party service from my Outlook Add-in, but no matter what I tried I receiving Error: Access is denied, and status 0 (request never hit the server).

Assuming we are running IE9 or 8 behind the outlook I tried old school hacks like https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest.

$.ajax({
    url: endpoint,
    data: JSON.stringify({'1':'2'}),
    // headers: {'X-Requested-With': 'XMLHttpRequest'},
    contentType: 'text/plain',
    type: 'POST',
    dataType: 'json',
    error: function(xhr, status, error) {
        // error
      }
}).done(function(data) {
    // done
  });

Is there is something more I need to implement? Of cause I add my domain to manifest AppDomain property.

Cheers

like image 779
yanik Avatar asked Mar 09 '23 12:03

yanik


1 Answers

The following needs to be done to send request to 3rd party service ...

  • Add the service URI to AppDomain list (you've done it.)
  • The service MUST have SSL endpoint; "https://your.domain" must be included within of "AppDomain" entry (see above)
  • The service has to allow CORS requests for your application (hosted Outlook App URI) domain or any domain. This is up to the service creators to allow or disallow client apps connections via Ajax.

As of observation of your code I notices you are sending JSON object, but setting content type to "text/plain". Contact the service creators to get information on what type of the data they accept as request. Usually services allow "application/json", but not plain text.

like image 143
Slava Ivanov Avatar answered Mar 19 '23 10:03

Slava Ivanov