I have this code in an external Javascript file:
async function sendIso3Info(inCurrency) {
let iso3Info = {
'text': inCurrency,
}
const response = await fetch(`/processIso3Info/${JSON.stringify(iso3Info)}`);
return await response.text();
}
Here is the part of my template with witch I want use the respond of the Fetch:
<script type="text/javascript">
currencyPair = "Wechselkurs " + "{{ srcCurrencyBlock['text'] }}" + " > " + " {{ destCurrencyBlock['text'] }}" + " "
let currencyFrom = "{{ srcCurrencyBlock['text'] }}"
let currencyTo = "{{ destCurrencyBlock['text'] }}"
// ----------------- Hier wird weitergearbeitet --------------------------------------
sendIso3Info(currencyFrom).then(res => console.log(res));
sendIso3Info(currencyTo).then(res => console.log(res));
// -----------------------------------------------------------------------------------
a = [['Tag-Monat-Jahr', 'Wert'],
{% for value in historyCurrencys %}
{% if value.From == 'EUR' and value.To == 'USD' %}
['{{ value.day }}-{{ value.month }}-{{ value.year}}', {{ value.close }}],
{% endif %}
{% endfor %}
]
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(function() { drawChart_1( a, currencyPair ); });
</script>
I want replace the 'EUR' and the 'USD' with the result of the fetch. How can I do it?
Patrick