Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

344
Vistas
Safari: Unable to retrieve parameters of an async function

I just made a function that displays a dialog on the page in Javascript, this function is asynchronous because it loads the dialog which is a page in PHP. However, to display the message I need to pass parameters. This function works very well, but does not work at all on Safari, when I display the parameters, on Safari it returns "undefined", while on MS Edge, it returns the parameter values. I tried with another non-asynchronous function, and it displays parameters fine. Do you think Safari doesn't handle parameters for async functions or am I doing it wrong? Thank you very much to the people who will help me. (Sorry for my bad English).

Function :

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 Respuestas
Responde la pregunta

0

The problem is that you're declaring new variables with the same names as the parameters. Since they're declared with var the declarations are hoisted to the top of the function, and the initial undefined value are overriding the parameters.

Either use different variables or just reassign them rather than re-declaring them.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda