javascript - Contact form using e.preventDefault(); not working live -


update - contact form found @ url.

i trying following contact form function, using tutorial.

i manage work expected on computer using apache webserver. after uploading files online website, ajax function not kick in. seems e.preventdefault(); stops working after upload, , form redirected new site,and not being processed on site without reload.

i have been trying use return false; instead of e.preventdefault(); without success.

her code:

.html

<form method="post" action='mail/mail.php'>     <label>name</label>     <input name="name" id="name" placeholder="name.." required="true" class="input-field">      <label>mail</label>     <input type="email" name="email" placeholder="mail.." required="true" class="input-field">      <label>msg</label>     <textarea name="message" id="message" class="textarea-field" required="true"></textarea>      <input type="submit" id="submit" name="submit" value="send"> </form>      <div id="loading">         sender melding...     </div>     <div id="success">     </div> 

.js

$(function(){       $('form').submit(function(e){         var thisform = $(this);         //prevent default form action          //return false;         e.preventdefault();          //hide form         $(this).fadeout(function(){           //display "loading" message           $("#loading").fadein(function(){             //post form send script             $.ajax({               type: 'post',               url: thisform.attr("action"),               data: thisform.serialize(),               //wait successful response               success: function(data){                 //hide "loading" message                 $("#loading").fadeout(function(){                   //display "success" message                   $("#success").text(data).fadein();               });             }           });         });       });     }) 

please help!

that's because js missing closing });. please check demo confirm default action indeed prevented , ajax kick in. however, expecting post instead seeing options request.

note: giving element name or id attribute value of submit bad practice. cannot example use javascript submit form via default form submission -- this.submit() or $('form')[0].submit() without getting error ...submit() not function .....

$(function() {        $('form').submit(function(e) {          var thisform = $(this);          //prevent default form action            //return false;          e.preventdefault();            //hide form          $(this).fadeout(function() {            //display "loading" message            $("#loading").fadein(function() {              //post form send script              $.ajax({                type: 'post',                url: thisform.attr("action"),                data: thisform.serialize(),                //wait successful response                success: function(data) {                  //hide "loading" message                  $("#loading").fadeout(function() {                    //display "success" message                    $("#success").text(data).fadein();                  });                }              });            });          });        });    }); // <==== missing this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <form method="post" action='mail/mail.php'>    <label>name</label>    <input name="name" id="name" placeholder="name.." required="true" class="input-field">      <label>mail</label>    <input type="email" name="email" placeholder="mail.." required="true" class="input-field">      <label>msg</label>    <textarea name="message" id="message" class="textarea-field" required="true"></textarea>      <input type="submit" id="submit" name="submit" value="send">  </form>    <div id="loading">    sender melding...  </div>  <div id="success">  </div>


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -