[Solved] send form to php file using ajax [closed]


Simple…

Change your HTML to this…

<form id="myform" name="myform" method='post' action="">
   <input name="name" type="text"/></br>
   <input name="email" type="text"/></br>
   <input name="title" type="text"/></br>
   <textarea name="message"></textarea></br>
   <button id="submitbutton">SUBMIT</button>
</form>

Include Jquery library at top of page…

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

Then add this script on the page…

<script>
$(document).ready(function(){

 $('#submitbutton').click(function(e){
   e.preventDefault();
   form = $("#myform").serialize();

   $.ajax({
     type: "POST",
     url: "yourpage.php",
     data: form,
     success: function(data){
         alert('Successful!'); 
     }});

   return false;  //stop the actual form post !important!
  });

});
</script>

THe processing on the other side is PHP….and Im not gonna show you that part….cuz I assume you already know how to process forms on the server side.

0

solved send form to php file using ajax [closed]