[英]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函数本身只是提供的示例函数。
请注意,如果要在其上添加*,则必须删除所有其他允许的原始类型,因为我从这里开始浪费了3-4个小时,在那里添加了localhost和所有内容,所以一切都失败了,最后我什么也没做根据指示,我删除了所有允许的原点,并在不到一秒的时间内得到了输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.