Refresh page after action

Asked

Viewed 12,797 times

2

I have a function to change records in the database and use a modal to show success or error message in the change.

The point is I can delete, but I would like after this function to be completed the page automatically gives a refresh.

elseif(isset($_GET['Acao']) && $_GET['Acao'] == 'Alterar') {
   $Id = $_GET['Id'];
     $sql = mysql_query("UPDATE vendas SET Mostrar = '0' WHERE Id = '$Id' ");

     if ($sql){
       echo '<script>modal({type: "inverted", title: "INFORMAÇÃO!", text: "Aterado com Sucesso!"});
       </script>';}
      else {  
        echo '<script>modal({type: "error", title: "Ops!", text: "Erro ao Alterar!"});</script>';             
}

<table class="lista-clientes" width="100%""> 
<tbody>     
    <tr>
        <td align="center"></td>
    <td> 

    <select class="select_styled">
        <option value="">'.$dados['Pessoa'].' </option>
        <option value="">'.$dados['Venda'].'</option>
    </select>
    <center>
        <a href="?Id='.$dados['Id'].'&Acao=Alterar" class="btn btn-follow" style="text-decoration:none;">
            <span>Remover!</span>
        </a>
    </center>
    </td>
    </tr>
 </tbody>
</table> 
  • Hi Leo, while I believe that the response of Rafael solve your problem (you can use location.reload(); on the Javascript side as a function of callback modal) the fact that you need to do this seems strange to me. If you already have the id from the sale, why not simply remove the page information using Javascript? Maybe you’re looking to do something with Ajax...

3 answers

3

You can use JavaScript and php to reload the page.

Javascript

location.reload();

PHP

header('Refresh:0');

0

From what I understand, what you need is this:

<a href="#" onclick="window.opener.location.href='home.php'; window.close()"><input class="btn btn-warning" type="submit" value="Fechar Janela"></a>

Place this code on the confirmation page and this link to the user clicking it updates the page you set in "window.opener.location.href='home.php'

  • yes, the question is this would have some way to count a few seconds before upgrading or when I close the modal

  • because if I just update it gets the ? id=11&Acao=Change in the browser and displays the modal

0

To reload a page via javascript you can use one of the following options:

Javascript 1.0

window.location.href = window.location.pathname + "pagina";

Creates page history entry

Javascript 1.1

window.location.replace(window.location.pathname + "pagina");

Does not create page history entry

Javascript 1.2

window.location.reload();

Reload the cache page

window.location.reload(false);

Reload the cache page

window.location.reload(true);

Reload server page (force new GET)

Browser other questions tagged

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