/* * Main ready function */ // const searchButton = document.getElementById("searchButton"); // searchButton.addEventListener("click", function() { // console.log("TEST") // ajaxTycho; // }); document.addEventListener('DOMContentLoaded', function() { const searchButton = document.getElementById("searchButton"); searchButton.addEventListener("click", function() { // ajaxTycho; }); ajaxTycho(); }); // Main function for querying function ajaxTycho() { // This works too... // const urlParams = new URLSearchParams(window.location.search); // const query = urlParams.get('query'); const urlParams = new Proxy(new URLSearchParams(window.location.search), { get: (searchParams, prop) => searchParams.get(prop), //get: (searchParams, prop) => searchParams.getAll(prop), // use getAll because languages is array }); let query = urlParams.query; let collections = urlParams.collections; //let lang = urlParams.language; //let from = urlParams.from; //let to = urlParams.to; fastQuery(query, collections) return query } function fastQuery(query, collections, lang, from, to) { // Production search URL const queryURL = 'https://tekstnet.dk/api/2/query'; //const queryURL = 'https://text.dsl.dk/api/2/query'; // Development search URL //const queryURL = 'http://localhost:1314/api/2/query'; let data = { query: query, collections: collections, lang: lang, from_date: from, to_date: to, 'api-key': '1f05f367-5524-43bd-94f6-ba6890e820d3'}; $.ajax({ url: queryURL, type: 'GET', contentType: 'application/json; charset=UTF-8', dataType: 'json', data: data, timeout: 3000, async: true, complete: function() { // TODO: Hide loading icon }, success: function(response) { showResult(response.hits, query, collections) //document.getElementById('dictList').style.display = 'block'; }, beforeSend: function() { // TODO: Show loading icon }, error: function (xhRequest, ErrorText, thrownError) { console.log(xhRequest); console.log('xhRequest: ' + xhRequest + "\n"); console.log('ErrorText: ' + ErrorText + "\n"); console.log('thrownError: ' + thrownError + "\n"); } }); } function showResult(hits, query, collections) { if (hits.length > 0) { // Get the searchResults container and display it var element = document.getElementById('searchResults'); element.style.display = 'block'; // Build search result list let result = '

Søgeord: ' + query + '
' + hits.length +' resultater

'; document.getElementById('dictList').innerHTML += result; } }