gpt4 book ai didi

javascript - 从源 '...' 访问位于 'http://localhost' 的 XMLHttpRequest 已被 CORS 策略阻止

转载 作者:行者123 更新时间:2023-11-29 15:58:49 24 4
gpt4 key购买 nike

<分区>


我正在尝试使用 javascript 演示 api 调用以获得 Json 结果。这是我所做的:

<!DOCTYPE html>
<html>
<head>
</head>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<body>
<div class="render-form">
<script>
$(document).ready(function() {
$.ajax({
type: 'GET',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
url: 'http://127.0.0.1:8080/activiti-rest/service/form/form-data?taskId=21159',
dataType: 'json',
success: function (data) {
alert(JSON.stringify(data));
}
});
})
</script>
</div>
</body>
</html>

但是当我运行它的时候,我得到了一个错误:

Access to XMLHttpRequest at 'http://127.0.0.1:8080/activiti-rest/service/form/form-data?taskId=21159' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

在这里搜索了很多帖子后,我补充说:

headers:{    
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},

但它仍然无法解决该错误。我该如何解决这个问题?
如有任何回复,我们将不胜感激!
非常感谢!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com