Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda