以下是我的代码:
$(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.
我对本节完全陌生,不知道错误是什么。如果我能得到任何帮助就太好了。提前致谢。
如果您是从本地主机执行此操作并使用此应用程序的代理服务器,则可以通过这种方式执行此操作,或者您也可以按照此 URL https://github.com/Rob--W自托管并创建代理服务器/cors-任何地方/
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);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句