Send form without updating page

Asked

Viewed 7,862 times

1

I have a registration page and I wanted it to be sent my form the page did not update and open a div occult.

With the script below does not let my page refresh, but also does not send my form to the database:

<script>
            jQuery(document).ready(function(){
            jQuery('#meufrm').submit(function(){
            var dados = jQuery(this).serialize();

            jQuery.ajax({
            type: "POST",
            url: "vendas.php",
            data: dados,
            success: function( data )
            {                   
            if (data == "")

            }
            });

            return false;
            });
            });

That other script hidden my div that works just right:

<script type="text/javascript">

                function mostra() {
                    if (document.getElementById('teste').style.display == 'block'){
                        document.getElementById('teste').style.display = 'none';
                    }else {document.getElementById('teste').style.display = 'block'}
                }

            </script>
  • "but also does not send my form to the bank " - how so? can explain what fails?

  • type when I press the Ubmit button the page does not update and open the hidden div , more the form data is not sent to the database understands ?

  • @Matheusgoes and what does the console? bugs? on the network part shows the ajax request exiting? what arrives on the server? "sales.php" is the right file? what is the source of that file?

1 answer

0

Creates a button to give the submit.

HTML

<form action="" method="get" accept-charset="utf-8">        
    <input type="text">
    <input type="text">
    <input type="text">

    <input type="button" id="enviaDados" name="" value="Envia">
</form>

JS

$(document).ready(function(){
        $("#enviaDados").on('click', function(){
            $.ajax({
                url: 'vendas.php',
                cache: false,
                type: "POST",
                success: function(){

                }
            })
        });
    }); 

If you still have any problems, it can be in your file vendas.php.

  • i already have a button to give the Submit ,the poblema would be in my javascript code because as soon as I remove that part of the script " ː if (date == "") }" it sends normally

  • It’s because your if is not opening the keys. It’s just closing. if(data == ''"){ }. Missed opening.

  • I tried that way nothing else changed ;/

  • Gives any error ? See Chrome Inspect Element.

  • Opa aparece esse erro aqui "Refused to execute script from 'https://raw.github.c....maskedinput.js' because its MIME type ('text/Plain') is not Executable, and Strict MIME type checking is enabled."

  • It has nothing to do with that part of the script then. It has to do with this mask plugin.

Show 1 more comment

Browser other questions tagged

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