I am storing my json files in script tag. All the data are included in mutiple json files. I am getting the data with the help of fetch Api and then converting the response into JSON format. But when i try to access the dataset used in the currentScript, the second instance returns null and throws an error in the browser console as 'cannot read properties of undefined'
Here is the code that i am using
async function getDataset() {
const widgetID = document.currentScript.id;
const wc = "."+widgetID;
const fetchConfig = await fetch(document.currentScript.dataset.config);
const config = await fetchConfig.json();
const fetchCurrency = await fetch(document.currentScript.dataset.currency);
const curreny = await fetchCurrency.json();
}
HTML:
<script async src="js/widget.js" data-config="js/config.json" data-currency="js/currency.json"></script>