Send POST AJAX request from Office Add-In

烈酒焚心 提交于 2019-12-19 09:08:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/45308473/send-post-ajax-request-from-office-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!