gpt4 book ai didi

javascript - json api get请求错误

转载 作者:行者123 更新时间:2023-12-01 02:46:18 25 4
gpt4 key购买 nike

以下是我的代码:

$(document).ready(function(){
$.ajax({
url: 'https://bitconnect.co/api/info/BTC_BCC',
type: 'get',
dataType: 'json',
success: function(data){
alert(data);
},
error: function(error){
alert(error);
}
});
});
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src = "//code.jquery.com/jquery-1.12.4.js"></script>

<script src="try.js"></script>
</head>
<body>

</body>
</html>

我想从ajax的url部分提到的url中获取信息。但我收到以下错误:

Failed to load https://bitconnect.co/api/info/BTC_BCC: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

我对这一部分完全陌生,不知道错误是什么。如果我能得到任何帮助,那就太好了。提前致谢。

最佳答案

如果您从本地主机执行此操作并使用此应用程序的代理服务器,则可以通过这种方式执行此操作,或者您也可以通过以下网址 https://github.com/Rob--W/cors-anywhere/ 自托管并创建代理服务器

var proxyUrl = 'https://cors-anywhere.herokuapp.com/'

$.ajax({
url: proxyUrl+'https://bitconnect.co/api/info/BTC_BCC',
type: 'get',
dataType: 'json',
crossDomain: true,
headers: { "Access-Control-Allow-Origin": "*" },
}).done(function(data) {
console.log(data);
});

关于javascript - json api get请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47237815/

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