'how to add search in select option when data fetching from ajax call
search bar is added but data not fetching in selectize jquery and at the normal side are working fetch data option tag but after adding search bar in drop down it can not working so please help
Solution 1:[1]
This is the simple version of your task. So may be it will helpful for you:
let url = 'https://rickandmortyapi.com/api/character/?page=1';
let isOpen = false;
const select = document.querySelector('#characters');
const getCharacters = (isFirstRun) => {
if (!isFirstRun) {
isOpen = !isOpen;
if (isOpen) return;
}
fetch(url)
.then(response => response.json())
.then(charactersData => {
url = charactersData.info.next;
select.innerHTML = '';
return charactersData.results.map(charactersData => charactersData.name);
})
.then(charactersNames => charactersNames.forEach(characterName => {
const option = document.createElement('option');
option.innerText = characterName;
select.appendChild(option);
}))
.catch(e => console.log(e.message));
}
getCharacters(true);
<select id="characters" onclick='getCharacters()'></select>
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | EzioMercer |
| Solution 2 | aWebDesigner123 |
