I have function like that
function cryptChange(cr){
var url = 'https://min-api.cryptocompare.com/data/dayAvg?fsym=' + cr + '&tsym=PLN';
console.log(url); // it's just for testing in console
};
cryptChange('LTC');
cryptChange('BTC');
As you can see this code is working fine with URL of AJAX call with JSON data, returning valid URL. Want to make something like that, but in shorter version, I have many lines of code like the ones below and I do want to get less
$.getJSON('https://min-api.cryptocompare.com/data/dayAvg?fsym=BTC&tsym=PLN', function(btc2){
$('#tt-11').html(btc2.PLN.toFixed(2)); //its passed into html block
});
$.getJSON('https://min-api.cryptocompare.com/data/dayAvg?fsym=BCH&tsym=PLN', function(bch2){
$('#tt-12').html(bch2.PLN.toFixed(2));
});
And now I want to mix that cryptChange function with AJAX call to pass parameter for callback and use that in $ ('#tt-11').html (btc2 here <==.PLN.toFixed (2);
Is that clearer guys now?
https://min-api.cryptocompare.com/data/dayAvgin it, use that variable for your url, and then give data as{fsym:'BTC', sym:'PLN'}or whatever, and getJSON will construct the url for you. This is a side note to whatever you as asking for at the bottom of your question.