JQuery: getJSON request not working

I am trying to access data using jQuery's getJSON function, but could not succeed.

This is my js file:

$(document).ready(function(){
  $("button").click(function(){

    $.getJSON( "https://www.bitstamp.net/api/eur_usd/", function( data ) {
    alert(data);
    });
  });
});

Can someone help me in getting this job?

We will be very grateful.

+4
source share
2 answers

try to get an error when calling ajax

$(document).ready(function() {
        $("button").click(function() {

            $.getJSON("https://www.bitstamp.net/api/eur_usd/", function(data) {
                    alert(data);
                }
                .error(function(xhr) {
                    alert(xhr)
                })
            );
        });
    });

Note. Xhr.responseText will give you an error stack trace, it will return in html format

+9
source

Must be used JSON.stringify(data)instead of data

0
source

All Articles