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

-1

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

I have this code working below,

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 it to return to within a given DIV, and I tried to do it as 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?

    
asked by anonymous 21.07.2018 / 05:18

1 answer

1

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

It also has a syntax error on this line, where ; should be : :

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

This does not stand a chance because meta refresh with content equal 0 will update the page countless times.

Do this by assigning to 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; ?>
    
21.07.2018 / 06:56