as I'm still learning, after hours of trying I still couldn't work out how to manage this Ajax call in my WP and get it to work. What I want to do is extract the "price" (USD) into a variable for further use.
This is my JSON object:
{
"data": {
"id": xx,
"name": "xx",
"symbol": "xx",
"rank": xx,
"quotes": {
"USD": {
"price": xx,
"volume_24h": xx,
"market_cap": xx,
"percent_change_1h": xx,
}
},
"last_updated": xx
},
}
And here's what I'm currently doing:
(function(getPrice) {
$j.ajax({
url: 'https://widgets.coinmarketcap.com/v2/ticker/3012/',
type: 'GET',
async: false,
data: 'data',
}).then(function(data) {
console.log(data);
});
})();
This gets me to log the whole "data", but after Google and StackOverflow I am still stuck. I figured it was just "data.quotes.USD.price", but apparently it isn't.
I would be very thankful vor every advice!
dataand the first property of the object is alsodata, so the access would start off asdata.data. This is, of course, provided that the ajax method already parsed the response, otherwise you need toJSON.parse(data)first