I am getting this json via ajax:
[{"currency_value":"1.00","currency_code":"47","type":"BUY"},{"currency_value":"1.00","currency_code":"47","type":"SELL"}]
However i want to use only the one who has the type of "SELL"
var setcurrencyvalue = function(to, value) {
parseInt($(to).attr('value', value)); // set the currency val
calculatetotal();
$('.amount-remaining').val(0);
//set the amount
}
var showcurval = function(cur_code) {
var $curcode = '';
var $currency = $('.currency-czk');
$.ajax({
type: 'GET',
url: '/transactions/get_currency_val?cur_code=' + cur_code,
success: function(data) {
var obj = JSON.parse(data);
$.each(obj, function (k, v) {
// console.log(v);
switch (v.currency_code) {
case '47':
$curcode = '€'; // 1
setcurrencyvalue($currency, v.currency_value);
break;
case '33':
$curcode = 'Kč'; // CZK/EUR
setcurrencyvalue($currency, v.currency_value);
break;
case '131':
$curcode = '₽'; //CZK/RUB
setcurrencyvalue($currency, v.currency_value);
break;
case '144':
$curcode = '$'; //CZK/USD
setcurrencyvalue($currency, v.currency_value);
break;
case '168':
alert('Please set a currency!');
break;
}
});
}
});
}
This will give me the the v.currency_value
randomly there are two of them. how to tell Ajax to work only with "SELL" or "BUY"?