I have problems passing the value in a declared into another var. Not sure of the syntax.
Currently in my code below, the <span id="xevalue1"></span>
in my html, it returns nothing, ie, blank. However if I change my script code to $('#xevalue1').append(info.AUD)
, it does retrieves the AUD values from the json data extracted from http://api.fixer.io/latest?base=USD.
The following is my code. Can someone help?
<!doctype html>
<html lang="en">
<head>
</head>
<body>
USD $1 = <span id="xelabel1"></span> $<span id="xevalue1"></span><br>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var url0 = 'http://api.fixer.io/latest?base=USD';
var cur1 = "AUD" //Australian Dollar
window['xeCallback1'] = function(data) {
var info = data.rates;
$('#xelabel1').append(cur1); //label for currency
$('#xevalue1').append(info.cur1); //extract json value from rates.AUD
};
$.ajax({
url: url0,
dataType: 'jsonp',
cache: true,
jsonpCallback: 'xeCallback1'
});
});
</script>
</body>
</html>