"Uncaught SyntaxError: Unexpected token:" error when trying to fetch data in JSON format from another URL

1

I'm trying to get data from a URL that returns JSON to use on my page. Apparently I'm getting the data, but for some reason I get the following error in the browser console:

  

"Uncaught SyntaxError: Unexpected token:".

For the moment, the only thing I'm doing is fetching the data and playing on log of the console with jquery . the code I'm using is as follows:

function logResults(json){
console.log(json);
}

$.ajax({
url: "https://blockchain.info/pt/ticker",
dataType: "jsonp",
jsonpCallback: "logResults"
});
    
asked by anonymous 26.07.2016 / 03:27

1 answer

0

I needed to make some changes to work:

dataType: "jsonp" to dataType: "json" ;

jsonpCallback: "logResults" to success: logResults

$.ajax({
        url: "https://blockchain.info/pt/ticker",
        dataType: "json",
        success:  logResults,               
});

Summarizing the return type is json and not jsonp .

Because it is not jsonp callback jsonpCallback is not called.

To get the return it is necessary to use callback success .

    
26.07.2016 / 03:42