Вот выполнение моего JavaScript: < /p>
ee_btn.addEventListener('click', () => {
//Ajax GET request to get data form and rendering it
RequestEEFormData(container, bounds).then(()=>{
// Loading a javascript file. it get loaded.
// I can call function from this file then.
loadScript('/static/js/locationConverterWidget.js');
});
});
< /code>
function loadScript(url) {
const script = document.createElement('script');
script.src = url;
script.async=false;
script.onload = function(){
//trying to querySelector newly added content
console.log(document.querySelector('#id_item);
}
document.head.appendChild(script);
}
< /code>
in case:
async function RequestEEFormData(container, bounds) {
$.ajax({
type: 'GET',
url: 'someURL/',
success: function (response) {
container.innerHTML=response;
someFunction(bounds)
},
error: function(response){
console.log(response);
},
cache:false,
contentType: "application/json",
processData: false
});
}
< /code>
the console.log return an empty Nodelist.
if I do call the same consol.log from a button 1sec later. It work.
Clearly there is something with the async I dont understand.
Can anyone explain my what I'm doing wrong ?
the purpose is I want the newly downloaded javascript file to querySelector newly added content but It seems to be executed prior the html is completely rendered.
thank you
Подробнее здесь: https://stackoverflow.com/questions/795 ... -execution
JavaScript Dynamic JavaScript Загрузка файла, затем выполнение ⇐ Javascript
Форум по Javascript
-
Anonymous
1745532052
Anonymous
Вот выполнение моего JavaScript: < /p>
ee_btn.addEventListener('click', () => {
//Ajax GET request to get data form and rendering it
RequestEEFormData(container, bounds).then(()=>{
// Loading a javascript file. it get loaded.
// I can call function from this file then.
loadScript('/static/js/locationConverterWidget.js');
});
});
< /code>
function loadScript(url) {
const script = document.createElement('script');
script.src = url;
script.async=false;
script.onload = function(){
//trying to querySelector newly added content
console.log(document.querySelector('#id_item);
}
document.head.appendChild(script);
}
< /code>
in case:
async function RequestEEFormData(container, bounds) {
$.ajax({
type: 'GET',
url: 'someURL/',
success: function (response) {
container.innerHTML=response;
someFunction(bounds)
},
error: function(response){
console.log(response);
},
cache:false,
contentType: "application/json",
processData: false
});
}
< /code>
the console.log return an empty Nodelist.
if I do call the same consol.log from a button 1sec later. It work.
Clearly there is something with the async I dont understand.
Can anyone explain my what I'm doing wrong ?
the purpose is I want the newly downloaded javascript file to querySelector newly added content but It seems to be executed prior the html is completely rendered.
thank you
Подробнее здесь: [url]https://stackoverflow.com/questions/79591515/javascript-dynamic-javascript-file-loading-then-execution[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия