I am new to JSON and web developing stuffs. So pardon me if I unable to present the problem in proper terms.
Here's the situation where I received JSON response from the site, however unable to display the response data with an error prompted out in the console.
I tried in firefox and chrome. Both of them gave me different errors.
Firefox = "SyntaxError: missing ; before statement
Chrome = "Uncaught SyntaxError: Unexpected token :"
I already tried two types of calling through jQuery API. Below are my sample code.
<html>
<body>
<button>Click Me!</button>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$("button").click(function()
{
$.getJSON("http://rate-exchange.herokuapp.com/fetchRate?from=SGD&to=MYR&lang=en-us&format=json&jsoncallback=?", function(data) {
console.log(data);
var info = JSON.parse(data);
alert(rate);
});
})
</script>
</body></html>
<html>
<body>
<button>Click Me!</button>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$("button").click(function loadRate()
{
$.ajax({
type:'GET',
url:"http://rate-exchange.herokuapp.com/fetchRate",
data:"from=SGD&to=MYR"+"&lang=en-us&format=json&jsoncallback=?",
dataType:'json',
success:function(resp){
var parse = JSON.parse(resp);
alert(parse.Rate);
}
});
})
</script>
</body></html>
And the JSON API i refer to is : http://rate-exchange.herokuapp.com/
The response data is like this : {"To":"MYR","From":"SGD","Rate":"2.5666"}