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

Comments

Popular posts from this blog

Youtube Error "Can't create new account because of past account issues"-Unsolved

Announcing the Keynote Speakers for PyCon 2016

A look at how Caktus Group built PyCon 2015, Libya's SMS voter registration, and more