0

i didint get any result from this code why ? im using coingecko api and triyng to get some info of crypto market

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="styyley.css">
</head>

<body>

    <div id="clist">
        <p></p>
    </div>


    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="jqu.js"></script>
</body>

</html> 
$(document).ready(function () {
        $.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=1&sparkline=false",function (data) {
                 $("#clist").append("hello"+data);
        });
    });
data data
  • 29
  • 5
  • 1
    the ajax call returns a very large json object. You are appending that object instead of the data you want from it. console.log the data variable, look at what it contains, and append using a loop and the data in the object – Gert B. Aug 26 '21 at 12:52
  • ok how can i choose what the type of data i want get ? – data data Aug 26 '21 at 13:03
  • The data is in the json object. since the json contains an array you can loop it. search online how to do that . – Gert B. Aug 26 '21 at 13:06
  • `data` is an array of objects. There's no such thing as a 'JSON object'. To retrieve data from it you need to loop through the array, accessing the necessary properties of the object and outputting them as necessary. From your use of `append()` I can see you know how to update the DOM, so I've linked a duplicate above which details how to loop through the array and access the object.s – Rory McCrossan Aug 26 '21 at 13:16
  • And the answer to why you get [object Object] is that you prepend a string which results in the toString method of your object is used and that returns `[object Object]`. Same if you `console.log("hello+data)` instead of `console.log("hello",data)` – mplungjan Aug 26 '21 at 13:42

1 Answers1

-2

You may need to try this

$(document).ready(function () {
    $.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=1&sparkline=false",function (data) {
            var parsed_data = JSON.stringify(data);
            $("#clist").append("hello"+parsed_data);
    });
});

That will convert the whole object into a string then you can concatenate and show as a string for your testing. However you need to loop through the Object you got in response as it is an array of objects.