【发布时间】:2018-12-09 08:48:54
【问题描述】:
我正在尝试使用 ajax 调用从 .net core web api 中提取数据,但出现以下错误
无法加载 http://localhost:8085/api/menu:预检响应包含无效的 HTTP 状态代码 404。
但我已成功从邮递员那里获取数据。
我正在尝试下面的 ajax 代码
$(document).ready(function(){
$.ajax({
url: 'http:/localhost:8085/api/menu',
type: 'GET',
dataType: 'json',
data: '{ }',
success: function (data) {
console.log(data);
},
failure: function (data) {
alert(data.responseText);
}, //End of AJAX failure function
error: function (data) {
alert(data.responseText);
}
});
});
我在 web.config 文件中添加了下面的标签
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
请提出您的想法。 提前谢谢。
【问题讨论】: