This commit is contained in:
girault
2022-05-10 12:21:29 +02:00
parent e3c07b83d4
commit 8e1ed459d1
7 changed files with 199 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
function debounce(fn, wait)
{
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), wait);
}
}
function autocomplete(datalist,communes)
{
// À compléter
datalist.innerHTML = '';
for(let c of communes) {
let option = document.createElement("option");
option.value = c;
datalist.appendChild(option);
}
}

View File

@@ -0,0 +1,30 @@
let http={
getVilles(nom){
// À compléter
let final_json;
return fetch('https://geo.api.gouv.fr/communes?nom=' + nom + '&fields=departement&boost=population&limit=7')
.then(readResponseAsJson)
.then(function(body) {
final_json = new Array();
body.forEach(el => final_json.push(el.nom));
return final_json
})
}
}
function readResponseAsJson(response){
if (!response.ok) {
console.log(response.statusText);
}
else {
return response.json()
}
}