Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
Safari: no se pueden recuperar los parámetros de una función asíncrona

Acabo de crear una función que muestra un cuadro de diálogo en la página en Javascript, esta función es asíncrona porque carga el cuadro de diálogo que es una página en PHP. Sin embargo, para mostrar el mensaje necesito pasar parámetros. Esta función funciona muy bien, pero no funciona en absoluto en Safari, cuando muestro los parámetros, en Safari devuelve "indefinido", mientras que en MS Edge devuelve los valores de los parámetros. Probé con otra función no asíncrona y muestra bien los parámetros. ¿Crees que Safari no maneja parámetros para funciones asíncronas o lo estoy haciendo mal? Muchas gracias a la gente que me va a ayudar. (Perdón por mi mal ingles).

Función :

 async function openDialogInfo(title, message, button) { alert(title + ' ' + message + ' ' + button); var title = (typeof title !== 'undefined') ? encodeURI(title) : 'Information'; var message = (typeof message !== 'undefined') ? encodeURI(message) : 'Error retrieving message !'; var button = (typeof button !== 'undefined') ? encodeURI(button) : 'Ok'; if (title.length >= 3 && message.length >= 5 && button.length >= 3) { if (screen.width >= 720) { $("#out-popup-e").css({ 'opacity': '0' }).show(); } else { $("#out-popup-e").show(); } var params = `title=${title}&message=${message}&bouton=${button}`; var resp = await fetch('../../../popup/popup_ecars_info.php', { method: "POST", body: params, headers: { "Content-type": 'application/x-www-form-urlencoded' } }); var out = await resp.text(); if (resp.status == '200') { if (screen.width >= 720) { $("#out-popup-e").animate({ 'opacity': '1' }, 400).html(out); } else { $("#out-popup-e").html(out); $(".center-popup").css({ 'bottom': '-700px' }).animate({ 'bottom': '0' }, 400); } } else { console.error('Error Message 2'); } } else { console.error('Error message 1'); } }
 <button class="action" onclick="openDialogInfo('HELLO WORLD', 'New message for testing (don\'t work on Safari)')">TEST</button> <button class="no-action" onclick="autreTest('New Message (work)')">New test</button>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema es que estás declarando nuevas variables con los mismos nombres que los parámetros. Dado que se declaran con var , las declaraciones se elevan a la parte superior de la función y el valor indefinido inicial anula los parámetros.

Use diferentes variables o simplemente reasígnelas en lugar de volver a declararlas.

 async function openDialogInfo(title, message, button) { alert(title + ' ' + message + ' ' + button); title = (typeof title !== 'undefined') ? encodeURI(title) : 'Information'; message = (typeof message !== 'undefined') ? encodeURI(message) : 'Error retrieving message !'; button = (typeof button !== 'undefined') ? encodeURI(button) : 'Ok'; if (title.length >= 3 && message.length >= 5 && button.length >= 3) { if (screen.width >= 720) { $("#out-popup-e").css({ 'opacity': '0' }).show(); } else { $("#out-popup-e").show(); } var params = `title=${title}&message=${message}&bouton=${button}`; var resp = await fetch('../../../popup/popup_ecars_info.php', { method: "POST", body: params, headers: { "Content-type": 'application/x-www-form-urlencoded' } }); var out = await resp.text(); if (resp.status == '200') { if (screen.width >= 720) { $("#out-popup-e").animate({ 'opacity': '1' }, 400).html(out); } else { $("#out-popup-e").html(out); $(".center-popup").css({ 'bottom': '-700px' }).animate({ 'bottom': '0' }, 400); } } else { console.error('Error Message 2'); } } else { console.error('Error message 1'); } }
 <button class="action" onclick="openDialogInfo('HELLO WORLD', 'New message for testing (don\'t work on Safari)')">TEST</button> <button class="no-action" onclick="autreTest('New Message (work)')">New test</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!