I am getting "undefined" when making an HTTP get request, but only the first time I make the request. The second time and on the code seems to work perfectly fine.
Below is my code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
let myData = "";
let dataTest = "";
$(document).ready(function(){
$("button").click(function(){
$.get("https://api.coinmarketcap.com/v1/ticker/ethereum/", function(data, status){
myData = data[0];
});
document.getElementById("p1").innerHTML = (myData.price_usd);
});
});
</script>
</head>
<body>
<p>If you want to get the price of Ethereum, press the following button:</p>
<button>Submit</button>
<p id="p1">
</p>
</body>