Clear URL after Insert

Asked

Viewed 131 times

0

I have a php Insert that redirects me to a page showing a success/error message through the url result, how can I update the url after the Alert script runs?

For example the url is: php? msg=error I wish she’d come back to: php.

<?php
if (isset($_GET['msg']) && $_GET['msg'] == 'error') {
    echo '
        <div class="alert alert-danger" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Erro!</strong> Cadastro não efetuado.
        </div> ';
        }elseif (isset($_GET['msg']) && $_GET['msg'] == 'success'){
            echo '
            <div class="alert alert-success" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <strong>Successo!</strong> Cadastro efetuado.
            </div>   
            ';
            }
?>

<script>
    window.setTimeout(function() {
        $(".alert").fadeTo(500, 0).slideUp(500, function(){
            $(this).remove(); 
        });
    }, 4000);
</script>
  • How so change the URL? Explain better by editing the question, please.

  • All right, I edited.

  • You can’t just change the call to POST?

2 answers

1


Try this way with JS, I recently drafted a project where I also had to clear all the parameters in the url, and this was the easiest and most functional way I could.

 var newURL = location.href.split("?")[0];
 window.history.pushState('object', document.title, newURL)
  • I was able to solve using: window.history.replaceState(null, null, window.location.pathname);

  • I am glad to have found a solution

0

Explain better.

<script>
    window.setTimeout(function() {
        $(".alert").fadeTo(500, 0).slideUp(500, function(){
            $(this).remove();
            window.location.reload();
        });
    }, 4000);
</script>

Refresh the page:

window.location.reload()

Back to the previous page:

javascript:history.back();

Redirect:

window.location.href="/";

Swap the url without updating the page:

window.history.pushState('Object', 'new url', '/');

Browser other questions tagged

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