javascript Боги! < /p>
У меня есть код JS здесь, который не работает. Может ли кто -нибудь указать, что я делаю здесь не так? Но слушатели событий, ответственные за обнаружение изменений в поле ввода, не работает.if (document.querySelector(".rooms-page")) {
// Room country filter
new RoomRegionFiter(
"id_country_input",
"country_datalist",
"region_datalist",
csrftoken);
}
< /code>
class RoomRegionFiter {
constructor (id_country_input, country_datalist, region_datalist, csrftoken) {
this.input = document.getElementById(id_country_input);
this.country_dataList = document.getElementById(country_datalist);
this.region_datalist = document.getElementById(region_datalist);
this.csrftoken = csrftoken;
this.initializeCountryEventListeners();
}
initializeCountryEventListeners() {
this.loadCountryList()
this.input.addEventListener("change", () => {
console.info("Listening for changes")
const selected_country = this.input.value;
this.loadRegionList(selected_country);
});
this.input.addEventListener("input", () => {
console.info("Listening for input")
const selected_country = this.input.value;
this.loadRegionList(selected_country);
});
};
// Loads all the countries on page load
async loadCountryList() {
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfiltercountry/`;
try {
const response = await fetch(endPoint, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
}
});
if (!response.ok) {
console.log("Response is not available");
}
const json_response = await response.json();
const countries = json_response.countries
let dataListOptions = ``;
for (const country of countries) {
dataListOptions += ``
}
this.country_dataList.innerHTML = dataListOptions
} catch (error) {
console.log(error.message);
}
}
// Whenever a country is selected, loads the regions
async loadRegionList() {
console.log("Building URL")
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfilterregion/`;
const url = `${endPoint}?country=${encodeURIComponent(selected_country)}`;
console.log(url)
try {
const response = await fetch(url, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
},
});
if (!response.ok) {
console.log("Response is not available");
}
const json_response = await response.json();
const regions = json_response.regions
console.log(json_response)
console.log(regions)
let dataListOptions = ``;
for (const region of regions) {
dataListOptions += ``
}
this.region_datalist.innerHTML = dataListOptions
} catch (error) {
console.log(error.message);
}
}
};
< /code>
Someone, please?
Подробнее здесь: https://stackoverflow.com/questions/795 ... s-not-fire
Ошибка загадки JavaScript - слушатель событий не уволен ⇐ Javascript
Форум по Javascript
-
Anonymous
1743624669
Anonymous
javascript Боги! < /p>
У меня есть код JS здесь, который не работает. Может ли кто -нибудь указать, что я делаю здесь не так? Но слушатели событий, ответственные за обнаружение изменений в поле ввода, не работает.if (document.querySelector(".rooms-page")) {
// Room country filter
new RoomRegionFiter(
"id_country_input",
"country_datalist",
"region_datalist",
csrftoken);
}
< /code>
class RoomRegionFiter {
constructor (id_country_input, country_datalist, region_datalist, csrftoken) {
this.input = document.getElementById(id_country_input);
this.country_dataList = document.getElementById(country_datalist);
this.region_datalist = document.getElementById(region_datalist);
this.csrftoken = csrftoken;
this.initializeCountryEventListeners();
}
initializeCountryEventListeners() {
this.loadCountryList()
this.input.addEventListener("change", () => {
console.info("Listening for changes")
const selected_country = this.input.value;
this.loadRegionList(selected_country);
});
this.input.addEventListener("input", () => {
console.info("Listening for input")
const selected_country = this.input.value;
this.loadRegionList(selected_country);
});
};
// Loads all the countries on page load
async loadCountryList() {
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfiltercountry/`;
try {
const response = await fetch(endPoint, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
}
});
if (!response.ok) {
console.log("Response is not available");
}
const json_response = await response.json();
const countries = json_response.countries
let dataListOptions = ``;
for (const country of countries) {
dataListOptions += ``
}
this.country_dataList.innerHTML = dataListOptions
} catch (error) {
console.log(error.message);
}
}
// Whenever a country is selected, loads the regions
async loadRegionList() {
console.log("Building URL")
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfilterregion/`;
const url = `${endPoint}?country=${encodeURIComponent(selected_country)}`;
console.log(url)
try {
const response = await fetch(url, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
},
});
if (!response.ok) {
console.log("Response is not available");
}
const json_response = await response.json();
const regions = json_response.regions
console.log(json_response)
console.log(regions)
let dataListOptions = ``;
for (const region of regions) {
dataListOptions += ``
}
this.region_datalist.innerHTML = dataListOptions
} catch (error) {
console.log(error.message);
}
}
};
< /code>
Someone, please?
Подробнее здесь: [url]https://stackoverflow.com/questions/79551490/javascript-mystery-error-event-listener-does-not-fire[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия