从Office加载项发送POST AJAX请求 [英] Send POST AJAX request from Office Add-In

查看:298
本文介绍了从Office加载项发送POST AJAX请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Outlook加载项发送对第三方服务的POST Ajax请求,但是无论我尝试了什么,我都收到了Error: Access is denied和状态为0(请求从未发到服务器上).

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

假设我们在前景上运行IE9或8,我尝试了诸如 https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest .

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

还有更多我需要实现的东西吗?当然,我将域添加到清单AppDomain属性.

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

欢呼声

推荐答案

需要完成以下操作,才能将请求发送到第三方服务...

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

  • 将服务URI添加到AppDomain列表中(您已经完成了.)
  • 该服务必须具有SSL端点; " https://your.domain "必须包含在"AppDomain"条目中(请参见上文)
  • 该服务必须允许您的应用程序(托管Outlook App URI)域或 any 域的CORS请求.服务创建者可以决定是否允许通过Ajax进行客户端应用连接.
  • 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.

从对代码的观察中,我注意到您正在发送JSON对象,但是将内容类型设置为文本/纯文本".请与服务创建者联系,以获取有关他们接受请求的数据类型的信息.通常,服务允许使用"application/json",但不允许使用纯文本.

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.

这篇关于从Office加载项发送POST AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆