how to use Coinmarketcap API using javascript(JS): Easy Method - ALLINTOFACT

Breaking News

how to use Coinmarketcap API using javascript(JS): Easy Method


how to use Coinmarketcap API using javascript(JS): Easy Method


how to use coinmarketcap api using javascript:

Copy this code and save this code as HTML page:

<!DOCTYPE html>
<html>
 <body>


<h2> Fetch Coinmaket API using Javascript </h2>

<!-- A button with click Event  LoadDoc function-->
 <button type="button" onclick="loadDoc()">Request data</button>

<!-- A paragraph where Output will be Printed -->

 <p id="demo">     </p>

<!-- Declaring Javascript script to fetch api & load in the paragraph demo -->
 <script> 
function loadDoc()
 {
 var xhttp = new XMLHttpRequest();
 xhttp.onreadystatechange = function()
{
 if (this.readyState == 4 && this.status == 200)
 {
 var myArray=JSON.parse(this.responseText);
 myFunction(myArray);
 }
 };
xhttp.open("GET", "https://api.coinmarketcap.com/v1/ticker/", true);
 xhttp.send();
 }
 function myFunction(arr)
 {
var out = "";
var i;
for(i = 0; i < arr.length; i++)
 {
out +=i+1+' '+arr[i].id +'  '+arr[i].symbol+'  '+arr[i].price_btc+ '<br>';
 }
document.getElementById("demo").innerHTML = out;
}
</script>
 </body>
</html>

I hope this post helped you to fetch Coinmarketcap API using Javascript. If you have any other method to fetch Coinmarketcap API then please, feel free to leave your comment.
Thank You

No comments