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

Asked

Viewed 538 times

1

I’m trying to pull data from a URL returning JSON to use on my page. Apparently I am able to bring the data, but for some reason I get the following error in the browser console:

"Uncaught Syntaxerror: Unexpected token :".

For now, the only thing I’m doing is bringing in the dice and playing log of the island by 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"
});
  • And then he managed to solve?

1 answer

0


I had to make some changes to make it work:

dataType: "jsonp" for dataType: "json";

jsonpCallback: "logResults" for success: logResults

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

Summarizing the type of return is json and not jsonp.

Because it is not jsonp the callback jsonpCallback is not called.

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

  • Vlw by tip, buddy, but when I make the suggested changes I have another error: "Xmlhttprequest cannot load https://blockchain.info/pt/ticker. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost' is therefore not allowed access."

  • I got it here, I added it, I added a "proxy", before I added an "http://cors.io/? u" on the front, so the URL was: ["http://cors.io/? uhttps://blockchain.info/pt/Ticker"], then the data came. Muchas Gracias!

  • I’m having the same problem, if you can help me I appreciate

Browser other questions tagged

You are not signed in. Login or sign up in order to post.