How can I take the required info and send it to a div in the html page

0 votes

This is my js file :

window.onload=function(){

var anima = document.getElementById("crypto");
var ret = document.getElementById("btn");

ret.addEventListener("click",function(){

var ourRequest = new XMLHttpRequest() ;
ourRequest.open('GET','https://api.cryptonator.com/api/full/btc-usd');
ourRequest.onload = function(){

    var fdata = JSON.parse(ourRequest.responseText);
    //renderHTML(fdata);
    console.log( fdata);
};

ourRequest.send()

});

When I click on the button the BTC price must be visible in the div area of the hmtl page.

How can I achieve this ? This is the url https://api.cryptonator.com/api/full/btc-usd

The id of the div is crypto.

Sep 6, 2018 in Blockchain by slayer
• 29,350 points
565 views

1 answer to this question.

0 votes
window.onload=function(){

var anima = document.getElementById("crypto");
var ret = document.getElementById("btn");

ret.addEventListener("click",function(){

var ourRequest = new XMLHttpRequest() ;
ourRequest.open('GET','https://api.cryptonator.com/api/full/btc-usd');
ourRequest.onload = function(){

    var fdata = JSON.parse(ourRequest.responseText);
    // anima – your div with #crypto
    // fdata.ticker.price – your path in api to BTC price;
    anima.textContent = fdata.ticker.price;
};

ourRequest.send()

});

You can also try innerHTML, if you wan insert html tags in the future.

https://developer.mozilla.org/ru/docs/Web/API/Node/textContent

https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML

answered Sep 6, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
3,371 views
0 votes
1 answer

In a Blockchain, how difficult is it to modify the third to last block?

Technically, it's not difficult at all, all ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,790 points
834 views
0 votes
1 answer
0 votes
1 answer

How can I retrieve to and from address in transaction directly from blockchain?

The spending conditions, i.e., who is able ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,400 points
1,031 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,148 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,706 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,237 views
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,740 points
2,555 views
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,740 points
1,041 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP