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,050 points
32 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
• 27,630 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,010 points
314 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
61 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,330 points
63 views
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,340 points
65 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
126 views
0 votes
1 answer
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
• 27,630 points
147 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
• 27,630 points
40 views