Skip to content
Advertisement

Nothing happening after get JSON request

I am calling an API to return some data. I can see in dev tools the response is 200 successful, and in the network tab can see the returned data.

The problem I have is with displaying the data in my UI. At this stage all I want to do is display the returned data in an alert.

I have tried the following, but the alert doesn’t fire. I can’t see any errors in console, and if I visit the PHP file manually (substituting in the GET variables) there are no errors.

jQuery

JavaScript

PHP

JavaScript

The API response looks like this: https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=30&aggregate=1&e=CCCAGG

Advertisement

Answer

This checks isset which returns true or false and then checks if that true or false NOT equal to "Error":

JavaScript

If it isset then it returns true which is == to "Error". You need two separate checks. Depending on what is returned in case of error, maybe:

JavaScript

Or check for success:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement