Jquery json response value to a variable -


url http://www.freecurrencyconverterapi.com/api/convert/?q=usd-inr&compact=y

json response

{   "usd-inr": {     "val": 61.235   } } 

jquery

function convert_currency(){     var currency = $('#convertor select').val();     jquery.ajax({         type : 'get',         datatype: 'jsonp',         data : {             q : 'usd-' + currency,             compact : 'y'         },         url : 'http://www.freecurrencyconverterapi.com/api/convert/',         success : function(data){             var value = data[0].val;             $('#converted_amount').text(value);         }     }); } $(document).ready(function(){     convert_currency();     $('#convertor select').change(function(){         convert_currency();      }) }); 

but method not correct. var value = data[0].val; . please correct me...

try use:

var value = data["usd-inr"].val; 


since you've assigned currency value currency variable, can do:

var value = data["usd-" + currency].val; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -