Witam
Prośba o pomoc, co robię nie tak, że funkcja zwraca mi UNDEFINIED
document.addEventListener('DOMContentLoaded', (event) => { const equipmentHelmet = document.querySelectorAll('.equipment_helmet'); function all() { $.ajax({ type: "GET", url: './form/eq_helmet.php', success: function (response) { response = JSON.parse(response); if(response.length) { console.log(response); return { buttons: { Spam: ({ text: ' ', backgroundColor: 'transparent', buttonWithImage: true, imageFrame: 'url(/images/equipment/EQ_Common.webp)', imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)', imageOptSize: 'cover', imageOptPosition: 'center', imageOptRepeat: 'no-repeat', imageWidth: '80px', imageHeight: '80px', action: function(){ } }) } } } } }); } equipmentHelmet.forEach(div => { div.addEventListener('click', function() { $.confirm({ content: '', title: 'Zmień Budynek', closeIcon: true, action: console.log(all()), }); }); }); });
return się używa po za funkcją .ajax().
Ok już poprawiłem i zmieniłem całość
document.addEventListener('DOMContentLoaded', (event) => { const equipmentHelmet = document.querySelectorAll('.equipment_helmet'); function helmet() { return new Promise((resolve) => { $.ajax({ type: "GET", url: './form/eq_helmet.php', success: function (response) { response = JSON.parse(response); if(response.length) { // console.log(response); result = $.confirm( { content: '', title: 'Zmień Budynek', closeIcon: true, buttons: { Spam: { text: ' ', backgroundColor: 'transparent', buttonWithImage: true, imageFrame: 'url(/images/equipment/EQ_Common.webp)', imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)', imageOptSize: 'cover', imageOptPosition: 'center', imageOptRepeat: 'no-repeat', imageWidth: '80px', imageHeight: '80px', action: function(){ } } } }); resolve(result) ; } } }); }) } equipmentHelmet.forEach(div => { div.addEventListener('click', function() { helmet().then((data) => { console.log(data) }) }); }); });
Spam: ({ text: ' ', backgroundColor: 'transparent', buttonWithImage: true, imageFrame: 'url(/images/equipment/EQ_Common.webp)', imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)', imageOptSize: 'cover', imageOptPosition: 'center', imageOptRepeat: 'no-repeat', imageWidth: '80px', imageHeight: '80px', action: function(){ } })
Skoro tworzysz ten obiekt w odpowiedzi Ajax, to w odpowiedzi masz też informację ile masz stworzyć obiektów.
Wydaje mi się, że wszystko OK, jeśli coś nie tak dajcie znać
document.addEventListener('DOMContentLoaded', (event) => { const equipmentHelmet = document.querySelectorAll('.equipment_helmet'); function helmet(rodzaj, nazwaPL) { return new Promise(() => { $.ajax({ type: "GET", url: './form/eq_helmet.php', success: function (response) { response = JSON.parse(response); if(response.length) { var name = {}; $.http://www.php.net/each(response, function() { name[this['Name']] = {} name[this['Name']]['text'] = ' '; name[this['Name']]['backgroundColor'] = 'transparent'; name[this['Name']]['buttonWithImage'] = 'true'; name[this['Name']]['imageFrame'] = 'url(/images/equipment/EQ_Common.webp)'; name[this['Name']]['imageOptURL'] = 'url(/images/equipment/' + rodzaj + '_' + this['Name'] + '.webp)'; name[this['Name']]['imageOptSize'] = 'cover'; name[this['Name']]['imageOptPosition'] = 'center'; name[this['Name']]['imageOptRepeat'] = 'no-repeat'; name[this['Name']]['imageWidth'] = '80px'; name[this['Name']]['imageHeight'] = '80px'; name[this['Name']]['action'] = 'function(){}'; }); result = $.confirm( { content: '', title: nazwaPL, closeIcon: true, buttons: name } ); } } }); }) } equipmentHelmet.forEach(div => { div.addEventListener('click', function() { helmet('HELMET', 'Hełm') }); }); });
Czemu tak mieszasz że raz używasz jquery, raz natywny JS?
Pewnie z braku wiedzy
Wszystko co robię staram się robić sam, albo znaleźć i dopasować, niestety robię to hobbystycznie więc gdzieniegdzie wiedza jest, a gdzieniegdzie jej nie ma
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)