Blockchain getjson javascript XMLHttpRequest

I am trying to get information about a bitcoin address using the Blockchain.info API, but this does not work. I get the same error:

XMLHttpRequest cannot load https://blockchain.info/address/13DKdDeZcdLbGoNquWz8nHBnVpfBVkDitz?format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:57366' is therefore not allowed access.

My code is:

$.getJSON("https://blockchain.info/address/13DKdDeZcdLbGoNquWz8nHBnVpfBVkDitz?format=json",
function(data) {$('#blockchain').append(JSON.stringify(data));
});

I tried the same code with a different API and it works:

$.getJSON("http://btc.blockr.io/api/v1/address/txs/13DKdDeZcdLbGoNquWz8nHBnVpfBVkDitz",
function(data) {$('#blockr').append(JSON.stringify(data));
});

The problem is that I need information that is only available for blockchain APIs.

Any idea?

+4
source share
1 answer

Use instead dataType: 'jsonp':

$.ajax({
    url: 'https://blockchain.info/address/13DKdDeZcdLbGoNquWz8nHBnVpfBVkDitz?format=json',
    dataType: 'jsonp',
    success: function (data) {
        $('#blockchain').append(JSON.stringify(data));
    },
    error: function () {}
});
0
source

Source: https://habr.com/ru/post/1531827/


All Articles