// ============================================================================ // This JS code is used to fetch the data from a selected dataverse table. By calling the function fetchlist(listname) the data will be called from the web template (ListTemplates.html) // ============================================================================ async function fetchList(listName, timeoutMs = 10000) { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), timeoutMs); try { // Don't encode the listName const response = await fetch(`/custom-api?list=${listName}`, { method: 'GET', headers: { 'Accept': 'application/json' }, credentials: 'same-origin', signal: controller.signal }); clearTimeout(timeoutId); if (!response.ok) return []; const text = await response.text(); try { return JSON.parse(text); } catch { return []; } } catch { return []; } }