Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Funkcja zwraca Undefinied
topcio
post 20.04.2023, 05:19:59
Post #1





Grupa: Zarejestrowani
Postów: 140
Pomógł: 0
Dołączył: 14.01.2017

Ostrzeżenie: (0%)
-----


Witam

Prośba o pomoc, co robię nie tak, że funkcja zwraca mi UNDEFINIED

  1.  
  2. document.addEventListener('DOMContentLoaded', (event) => {
  3.  
  4. const equipmentHelmet = document.querySelectorAll('.equipment_helmet');
  5.  
  6. function all() {
  7. $.ajax({
  8. type: "GET",
  9. url: './form/eq_helmet.php',
  10. success: function (response) {
  11. response = JSON.parse(response);
  12. if(response.length) {
  13. console.log(response);
  14. return {
  15. buttons: {
  16. Spam: ({
  17. text: ' ',
  18. backgroundColor: 'transparent',
  19. buttonWithImage: true,
  20. imageFrame: 'url(/images/equipment/EQ_Common.webp)',
  21.  
  22. imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)',
  23. imageOptSize: 'cover',
  24. imageOptPosition: 'center',
  25. imageOptRepeat: 'no-repeat',
  26.  
  27. imageWidth: '80px',
  28. imageHeight: '80px',
  29.  
  30. action: function(){
  31.  
  32. }
  33. })
  34. }
  35.  
  36. }
  37. }
  38. }
  39. });
  40. }
  41.  
  42. equipmentHelmet.forEach(div => {
  43. div.addEventListener('click', function() {
  44. $.confirm({
  45. content: '',
  46. title: 'Zmień Budynek',
  47. closeIcon: true,
  48. action: console.log(all()),
  49. });
  50. });
  51. });
  52. });


Ten post edytował topcio 20.04.2023, 05:20:21
Go to the top of the page
+Quote Post
Tomplus
post 20.04.2023, 05:46:05
Post #2





Grupa: Zarejestrowani
Postów: 1 841
Pomógł: 226
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


return się używa po za funkcją .ajax().
Go to the top of the page
+Quote Post
topcio
post 20.04.2023, 06:33:19
Post #3





Grupa: Zarejestrowani
Postów: 140
Pomógł: 0
Dołączył: 14.01.2017

Ostrzeżenie: (0%)
-----


Ok już poprawiłem i zmieniłem całość

  1.  
  2. document.addEventListener('DOMContentLoaded', (event) => {
  3.  
  4. const equipmentHelmet = document.querySelectorAll('.equipment_helmet');
  5.  
  6. function helmet() {
  7. return new Promise((resolve) => {
  8. $.ajax({
  9. type: "GET",
  10. url: './form/eq_helmet.php',
  11. success: function (response) {
  12. response = JSON.parse(response);
  13. if(response.length) {
  14. // console.log(response);
  15. result =
  16. $.confirm(
  17. {
  18. content: '',
  19. title: 'Zmień Budynek',
  20. closeIcon: true,
  21. buttons: {
  22. Spam: {
  23. text: ' ',
  24. backgroundColor: 'transparent',
  25. buttonWithImage: true,
  26. imageFrame: 'url(/images/equipment/EQ_Common.webp)',
  27.  
  28. imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)',
  29. imageOptSize: 'cover',
  30. imageOptPosition: 'center',
  31. imageOptRepeat: 'no-repeat',
  32.  
  33. imageWidth: '80px',
  34. imageHeight: '80px',
  35.  
  36. action: function(){
  37.  
  38. }
  39. }
  40. }
  41. });
  42. resolve(result) ;
  43. }
  44. }
  45. });
  46. })
  47. }
  48.  
  49. equipmentHelmet.forEach(div => {
  50. div.addEventListener('click', function() {
  51. helmet().then((data) => {
  52. console.log(data)
  53. })
  54. });
  55. });
  56. });
  57.  
  58.  


Ale mam jeszcze jedno pytanie i prośbę o pomoc bo nie wiem jak to ugryźć

  1.  
  2. Spam: ({
  3. text: ' ',
  4. backgroundColor: 'transparent',
  5. buttonWithImage: true,
  6. imageFrame: 'url(/images/equipment/EQ_Common.webp)',
  7.  
  8. imageOptURL: 'url(/images/equipment/ACCESSORY_Ambrosial_Cup.webp)',
  9. imageOptSize: 'cover',
  10. imageOptPosition: 'center',
  11. imageOptRepeat: 'no-repeat',
  12.  
  13. imageWidth: '80px',
  14. imageHeight: '80px',
  15.  
  16. action: function(){
  17.  
  18. }
  19. })
  20.  
  21.  


w tym miejscu chciałbym zrobić tyle obiektów ile zwraca ajax, teraz dałem jeden ręcznie by zobaczyć czy działa.
Go to the top of the page
+Quote Post
trueblue
post 20.04.2023, 08:47:21
Post #4





Grupa: Zarejestrowani
Postów: 6 762
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Skoro tworzysz ten obiekt w odpowiedzi Ajax, to w odpowiedzi masz też informację ile masz stworzyć obiektów.


--------------------
Go to the top of the page
+Quote Post
topcio
post 20.04.2023, 10:24:39
Post #5





Grupa: Zarejestrowani
Postów: 140
Pomógł: 0
Dołączył: 14.01.2017

Ostrzeżenie: (0%)
-----


Wydaje mi się, że wszystko OK, jeśli coś nie tak dajcie znać

  1. document.addEventListener('DOMContentLoaded', (event) => {
  2.  
  3. const equipmentHelmet = document.querySelectorAll('.equipment_helmet');
  4.  
  5. function helmet(rodzaj, nazwaPL) {
  6. return new Promise(() => {
  7. $.ajax({
  8. type: "GET",
  9. url: './form/eq_helmet.php',
  10. success: function (response) {
  11. response = JSON.parse(response);
  12. if(response.length) {
  13. var name = {};
  14. $.each(response, function() {
  15. name[this['Name']] = {}
  16. name[this['Name']]['text'] = ' ';
  17. name[this['Name']]['backgroundColor'] = 'transparent';
  18. name[this['Name']]['buttonWithImage'] = 'true';
  19. name[this['Name']]['imageFrame'] = 'url(/images/equipment/EQ_Common.webp)';
  20. name[this['Name']]['imageOptURL'] = 'url(/images/equipment/' + rodzaj + '_' + this['Name'] + '.webp)';
  21. name[this['Name']]['imageOptSize'] = 'cover';
  22. name[this['Name']]['imageOptPosition'] = 'center';
  23. name[this['Name']]['imageOptRepeat'] = 'no-repeat';
  24. name[this['Name']]['imageWidth'] = '80px';
  25. name[this['Name']]['imageHeight'] = '80px';
  26. name[this['Name']]['action'] = 'function(){}';
  27. });
  28. result =
  29. $.confirm(
  30. {
  31. content: '',
  32. title: nazwaPL,
  33. closeIcon: true,
  34. buttons: name
  35. }
  36. );
  37. }
  38. }
  39. });
  40. })
  41. }
  42.  
  43. equipmentHelmet.forEach(div => {
  44. div.addEventListener('click', function() {
  45. helmet('HELMET', 'Hełm')
  46. });
  47. });
  48. });
  49.  
Go to the top of the page
+Quote Post
viking
post 20.04.2023, 10:49:11
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Czemu tak mieszasz że raz używasz jquery, raz natywny JS?


--------------------
Go to the top of the page
+Quote Post
topcio
post 20.04.2023, 10:53:05
Post #7





Grupa: Zarejestrowani
Postów: 140
Pomógł: 0
Dołączył: 14.01.2017

Ostrzeżenie: (0%)
-----


Pewnie z braku wiedzy wink.gif
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

Ten post edytował topcio 20.04.2023, 11:01:18
Go to the top of the page
+Quote Post
Sanjeev
post 25 minut temu
Post #8





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: Wczoraj, 11:37

Ostrzeżenie: (0%)
-----


Cytat(trueblue @ 20.04.2023, 09:47:21 ) *
Skoro tworzysz ten obiekt w odpowiedzi Ajax, to w odpowiedzi masz też informację ile masz stworzyć obiektów.

This suggests a dynamic process where Ajax responses not only create objects but also specify their quantity. It underscores the flexibility and efficiency of Ajax in managing object creation.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 7.05.2024 - 07:30