خرید بک لینک
I am using a client side loop to pull data from an API (specifically the BTC price from Bitstamp). This loop runs every 5 second. Around nine times out of ten I get a perfect response and its happy days however approximately one in ten times I will get:
Code:

Failed to load https://www.bitstamp.net/api/v2/ticker/btcusd: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
There seems to be no rhyme or reason to when it occurs. Itx92s not every tenth, it can be the first call, slowing the requests down does not help, and no other requests present this issue.
I feel I understand the error and what it is saying, but I donx92t understand how itx92s an intermittent error, it should either occur or not occur.

Any tips or guidance for this noob would be appreciated! Maybe even a beer :D

If it helps, the code is as bellow:
Code:

function retrieveBitstampLatestPrice() {

        console.log('retrieveBitstampLatestPrice');

        var xhr_method = 'GET';
        var xhr_url = 'https://www.bitstamp.net/api/v2/ticker/btcusd';
        var xhr_send = null;

        var xhr = new XMLHttpRequest();
        xhr.open(xhr_method, xhr_url, true);
        xhr.send(xhr_send);

        xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                                var response = JSON.parse(xhr.response);
                                //console.log(response);
                                bitstampLatestPrice = response.last;
                        } else {
                                console.log('Something went wrong! (' + xhr_url + ')');
                                console.log(xhr);
                        }
                }
        }
}

برچسب: نویسنده: آیلین رضوانی تاريخ: پنجشنبه 2 آذر 1396 ساعت: 16:25

صفحه بندی