【发布时间】: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