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

173
Vistas
How to return variable from php to javascript

I have this part of javascript, How do I return res.success and res.reload from php?

if (res.success) {
                    NioApp.Toast(res.success, 'success');
                    if (res.reload) {
                        setTimeout(function() {
                            location.reload();
                        }, 900);
                    }
                } 

I tried $return ['res' => 'success'] but didn't work for me.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The question is not that clear, But I am just trying to solve it. If you want to get the value from PHP to js, then either you need to use an async API call to the server to get the value. or you need to echo out the value to some HTML hidden elements and use javascript to get the value to a variable using getElement.But if you want to send the value to the server then use the get or post method.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I guess by 'res' you meant ajax response here, if so, you need to echo out json from php file.

PHP

<?
 $result = array("success" => "success", "reload" => "true");
 echo json_encode($result);
?>

Script

$.post("someFile.php", {//somedata},
  function(data, status){
  if(status == "success"){
  res = JSON.parse(data);
  //now here is your script
  if (res.success) {
                    NioApp.Toast(res.success, 'success');
                    if (res.reload) {
                        setTimeout(function() {
                            location.reload();
                        }, 900);
                    }
                } 
}
}
)

Comment down for any queries.

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