【问题标题】:Azure Function App - No header is presentAzure Function App - 不存在标头
【发布时间】:2016-08-14 12:40:19
【问题描述】:

我正在评估Azure Functions。为了做到这一点,我有一个在 localhost 上运行的网页。我想使用 JQuery 调用 Azure 函数并显示结果。为了尝试做到这一点,我有以下 HTML:

<button onclick="return onTestClick();">Test</button>

...

<script type="text/javascript">
  function onTestClick() {
    $.ajax({
      url: "https://[my-function-app].azurewebsites.net/api/[My-Function]?code=[myCode]&name=bill", 
      success: function(result){
        console.log(result);
      },
      error: function(xhr, status, err) {
        console.log(status);
        console.log(err);
        console.log(xhr);
      }
    });
    return false;
  }
</script>

当我点击按钮时,error 事件处理程序被触发。在控制台窗口中,我可以看到以下错误:

XMLHttpRequest 无法加载 https://[my-function-app].azurewebsites.net/api/[My-Function[?code=[myCode]&name=bill。 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://localhost:3000” 访问。

我的问题是,如何从在 localhost 上运行的 jQuery 调用 Azure 函数? Azure 函数本身只是提供的示例函数。

【问题讨论】:

  • 您是否尝试在功能应用设置中启用 CORS?
  • 请修正标题以反映问题。谢谢!

标签: jquery azure azure-functions


【解决方案1】:

您需要在 Azure 应用服务中启用 CORS。详情和截图是here

【讨论】:

  • 注意:从功能应用程序中,您首先需要转到“功能应用程序设置”和“转到应用程序服务设置”以访问与此链接匹配的 UI。
【解决方案2】:

请注意,如果要在其上添加 *,则必须删除所有其他允许来源类型,因为我已经成功地浪费了我 3-4 个小时从这里和那里添加 localhost 和所有内容,一切都失败了,最后我什么也没做按照指示,我删除了所有允许的来源,并在几分之一秒内得到了输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 2021-05-20
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多