繁体   English   中英

我正在尝试从bitbns.com获取json数据,但出现错误

[英]I am trying to get json data from bitbns.com but getting an error

我对javascript非常陌生,我正尝试从bitbns获取json数据,但出现错误-“(原因:CORS标头'Access-Control-Allow-Origin'与' https://www.bitbns.com '不匹配) ”。

我在互联网上进行了很多搜索,但找不到任何解决方案。

<script>

url="https://www.bitbns.com/order/getTicker";
var request = new Request(url);

fetch(request, {mode: "cors",
}).then(function(response) {
       return response.json();
    }).then(function(j) {
       console.log(JSON.stringify(j)); 
    }).catch(function(error) {  
        console.log('Request failed', error)  
    });
console.log(request.headers)
</script>

谁能帮我这个忙吗?

 var proxyUrl = 'https://cors-anywhere.herokuapp.com/' var url="https://www.bitbns.com/order/getTicker"; let x = proxyUrl + url fetch(x, {mode: "cors", }).then(function(response) { return response.json(); }).then(function(j) { console.log(JSON.stringify(j)); }).catch(function(error) { console.log('Request failed', error) }); 

这会使事情发生变化,但是由于缺乏安全性,最好不要将其用于生产。

https://cors-anywhere.herokuapp.com/是添加cors标头的链接。

这是我在https://www.sencha.com/forum/showthread.php?299915-How-to-make-an-ajax-request-cross-origin-CORS上找到的内容

$.ajax({
            url: 'http:ww.abc.com?callback=?',
            dataType: 'JSONP',
            jsonpCallback: 'callbackFnc',
            type: 'GET',
            async: false,
            crossDomain: true,
            success: function () { },
            failure: function () { },
            complete: function (data) {
                if (data.readyState == '4' && data.status == '200') {
                    errorLog.push({ IP: Host, Status: 'SUCCESS' })
                }
                else {
                    errorLog.push({ IP: Host, Status: 'FAIL' })
                }
            }
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM