You can use Ajax request in <meta http-equiv='refresh' content='0;'>

Asked

Viewed 252 times

-1

Friends can use a request on <meta http-equiv='refresh' content='0;'>.

I have this code below working,

if($buscasegura->execute() == '');
    echo "<meta http-equiv='refresh' content='0; prod_carrinho2.php'>
                  <script type=\"text/javascript\">
                  alert(\"Cliente cadastrado com sucesso!!!\");</script>";
else:
    echo "<meta http-equiv='refresh' content='0; cad_cliente.php'>
                  <script type=\"text/javascript\">
                  alert(\"Já existe uma conta cadastrada com esse E-mail!!!\");</script>";
endif;

and returning to a new page, either with the success of the registration or with the existence of the registered e-mail.

I would like him to return within a certain DIV, and tried to do it as follows below.

echo "<meta class='sucesso' http-equiv='refresh' content='0;'>
                      <script type=\"text/javascript\">
                      alert(\"Cliente cadastrado com sucesso!!!\");</script>";
else:
        echo "<meta class='erro' http-equiv='refresh' content='0;'>
                      <script type=\"text/javascript\">
                      alert(\"Já existe uma conta cadastrada com esse E-mail!!!\");</script>";
    endif;
}
?>

<script language="javascript">
////// Direciona o cliente para para suas compras, depois de executar o cadastro com sucesso //////
    $(document).ready(function(){
        $('.sucesso').click(function(){
            $.ajax({url:"prod_carrinho2.php",success:function(data){
                $('#visual').html(data);
                }
            });
        });
    });


////// Direciona o cliente para inserir um outro endereço de E-mail //////
    $(document).ready(function(){
        $('.erro').click(function(){
            $.ajax({url:"cad_cliente.php",success:function(data){
                $('#visual').html(data);
                }
            });
        });
    });
</script>

Can you identify a <meta http-equiv='refresh' content='0;'>, to make the Ajax request work, or not?

1 answer

1

The use of meta refresh is not for that, much less is a clickable element.

There is also a syntax error on this line, where the ; should be ::

if($buscasegura->execute() == '');
                                 ^

This has no chance to work because the meta refresh with content equal to 0 will update the page endlessly.

Do so by assigning the variable $url the page to be requested by Ajax according to the result of if:

<?php
if($buscasegura->execute() == ''):
   $url = 'prod_carrinho2.php';
   echo '<script>alert("Cliente cadastrado com sucesso!!!");</script>';
else:
   $url = 'cad_cliente.php';
   echo '<script>alert("Já existe uma conta cadastrada com esse E-mail!!!");</script>';
endif;
?>
<?php if(isset($url)): ?>
<script>
$(document).ready(function(){
   $.ajax({
      url:"<?php echo $url ?>",
      success:function(data){
         $('#visual').html(data);
      }
   });
});
</script>  
<?php endif; ?>
  • Thanks Sam, thanks for the tips, I am layman and I am trying to learn... I will put in practice your guidance and correct the mentioned error... Once again THANK YOU!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.