How to send the form without redirecting to another PHP page

Asked

Viewed 137 times

-1

How to send the form behind without redirecting to another page just clear the fields and display an alert or message that was sent, without refreshing the page, because I did so :

echo ("<SCRIPT LANGUAGE='JavaScript'>window.location.href='index.php';window.alert('Formulário enviado com sucesso!');</SCRIPT>");

But it still has a delay that shows the application running and then shows the alert and finally loads the page.

  • Study about AJAX. Right here on the site there is many questions about it.

  • You can study about the fetch javascript also.

2 answers

1


Hello you can do with Ajax, thus:

    $.ajax({
        // URL de destino
        url: 'index.php',
        type: 'post',
        // Suas variaveis serializadas EX: 'nome=Bruno&idade=24'
        data: dataString,
        cache: false,

        success: function (data)
        {
            // retorno do php
            alert('Formulário enviado com sucesso!');
        }
    });

0

Browser other questions tagged

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