简体   繁体   English

Azure Function应用-不存在标题

[英]Azure Function App - No header is present

I am evaluating Azure Functions . 我正在评估Azure函数 In an attempt to do this, I have a web page that runs on localhost. 为了做到这一点,我有一个在本地主机上运行的网页。 I want to use JQuery to call an Azure Function and display the result. 我想使用JQuery调用Azure函数并显示结果。 In an attempt to do this, I have the following HTML: 为了做到这一点,我有以下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>

When I click the button, the error event handler is triggered. 当我单击按钮时,将触发error事件处理程序。 In the console window, I can see the following error: 在控制台窗口中,我可以看到以下错误:

XMLHttpRequest cannot load https://[my-function-app].azurewebsites.net/api/[My-Function[?code=[myCode]&name=bill . XMLHttpRequest无法加载https:// [my-function-app] .azurewebsites.net / api / [My-Function [?code = [myCode]&name = bill) No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:3000 ' is therefore not allowed access. 因此,不允许访问源' http:// localhost:3000 '。

My question is, how do I call an Azure Function from jQuery that's running on localhost? 我的问题是,如何从在本地主机上运行的jQuery调用Azure函数? The Azure Function itself is just the sample function provided. Azure函数本身只是提供的示例函数。

You will need to enable CORS in the Azure App Service. 您将需要在Azure应用服务中启用CORS。 Details and screenshots are here . 详细信息和屏幕截图在此处

请注意,如果要在其上添加*,则必须删除所有其他允许的原始类型,因为我从这里开始浪费了3-4个小时,在那里添加了localhost和所有内容,所以一切都失败了,最后我什么也没做根据指示,我删除了所有允许的原点,并在不到一秒的时间内得到了输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Ajax调用控制器函数给出No&#39;Access-Control-Allow-Origin&#39;标头存在错误 - Calling a controller function using Ajax giving a No 'Access-Control-Allow-Origin' header is present error 如果存在div则激活功能 - Activating a function if a div is present 创建一个存在于网站栏标头中的表单 - creating a form that is present in header of site rails 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource WordPress 请求的资源上不存在“Access-Control-Allow-Origin”标头 - WordPress No 'Access-Control-Allow-Origin' header is present on the requested resource CORS访问控制允许起源头不存在 - Cors access-control-allow-origin header not present CORS错误:不存在“ Access-Control-Allow-Origin”标头 - CORS Error : No 'Access-Control-Allow-Origin' header is present CORS“没有&#39;Access-Control-Allow-Origin&#39;标题存在”但是有 - CORS “No 'Access-Control-Allow-Origin' header is present” yet there is 遇到请求的资源上没有&#39;Access-Control-Allow-Origin&#39;标头 - Encounter No 'Access-Control-Allow-Origin' header is present on the requested resource 所请求的资源上没有Access-Control-Allow-Origin&#39;标头 - NO Access-Control-Allow-Origin' header is present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM