Yanik Koval Yanik Koval - 3 years ago 88
Ajax Question

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
(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.

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


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download