如何解决延迟 iron-ajax 响应

How to Resolve Delayed iron-ajax Response

我正在尝试删除此 AJAX 请求中的错误。当 运行 这个 AJAX 调用它会快速加载模板,但一段时间后(我认为是超时),控制台会记录以下错误。

Failed to load https://api/endpoint:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://internal.msmni.com' is therefore not allowed access.

应用程序托管在 app.domain.com 的 IIS 上,API 端点位于 api.domain.com

<iron-ajax id="ajaxCustomers"
  url="https://api/endpoint"
  method="post"
  handle-as="json"
  content-type="application/json"
  body="[[request]]"
  last-response="{{response}}"
  loading="{{loading}}"
  headers="Access-Control-Allow-Origin"></iron-ajax>

...

<template is="dom-repeat" items="[[response]]" as="item">
  <p>[[customer]]</p>
</template>

有没有办法正确设置 header and/or 配置服务器来消除这个错误?

P.S.

我正在使用 Node 的 Express,我在 server.js 文件中设置了以下内容。

res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, content-type, Accept, Authorization, x-api-key")

错误 No 'Access-Control-Allow-Origin' header 意味着您的 api 没有在响应中设置 Access-Control-Allow-Origin header 因为这需要由服务器返回以允许中断Same-Origin 政策(在请求中包含它是不够的)请参阅:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

所以你的 api 应该设置一个 header 比如 Access-Control-Allow-Origin: app.domain.com 这样你的应用就可以读取数据。