I
I
Igor Vasiliev2019-01-26 23:38:18
JavaScript
Igor Vasiliev, 2019-01-26 23:38:18

How to get json file via javascript?

Hello.
It used to be somehow easier to get json files by reference, now it feels like something has changed.
Does not want to work, does not transmit anything, information 0 (zero), via console.log() and via alert()
sends NOTHING. Not even undefanted. Full zero. What is the problem and why it stopped working I do not understand.
If there is any other way - tell me. PHP is not suitable.
Here is the code itself that stopped working:

<!doctype>
<html lang="ru">
  <head>
    <meta charset="utf-8">
    <title>Веб-страница</title>
    <script>
       function loadJSON(callback) {   

        var xobj = new XMLHttpRequest();
        xobj.overrideMimeType("application/json");
        xobj.open('GET', 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-GBG', true);
        xobj.onreadystatechange = function () {
            if (xobj.readyState == 4 && xobj.status == "200") {
            callback(xobj.responseText);
            }
        };
        xobj.send(null);  
       }
      function init() {
       loadJSON(function(response) {
        var actual_JSON = JSON.parse(response);
        document.getElementById("data").innerHTML = actual_JSON.result[1].MarketName + " / " + actual_JSON.result[1].BaseVolume;
       });
      }
    </script>		
  </head>
  <body>
    <h1>Заголовок</h1>
    <div id="data"></div>
  </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ao, 2019-01-27
@darknefrit

You need to climb into bittrex and most likely add the url or ip from which you send the request so that the server gives you the Access-Control-Allow-Origin header: https://yourdomain
Otherwise, you are unlikely to succeed with js. At least through a browser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question