jcadima
5/18/2017 - 3:11 PM

Ajax without serialize

Ajax without serialize


<form action="" method="" id="event_form">
  <input name="name" id="name">
  <input name="email" id="email">
  <input name="age" id="age">
</form>

<script>
$(document).ready( function () {
	
	$("#event_form").submit(function(event) {
	   event.preventDefault();
		 var name = $('#name').val();
		 var email = $('#email').val();
		 var age = $('#age').val();
	
	    /* Clear result div*/
	    $("#result").html('');
	
	
	       ajaxRequest= $.ajax({
	            url: "check_event_domain.php",
	            type: "POST",
	            data: {name:name,email:email,age:age}
	        });
	
	      /*  request cab be abort by ajaxRequest.abort() */
	
	     ajaxRequest.done(function (response, textStatus, jqXHR){
	          // show successfully for submit message
	          console.log("SUCCESS") ;
	          $("#result").html(response);
	     });
	
	     /* On failure of request this function will be called  */
	     ajaxRequest.fail(function (){
	
	       // show error
	       console.log("ERROR") ;
	       $("#result").html('There is error while submit');
	     });
	
	});

	
}) ;
</script>




PHP

<?php

$name = $_POST['name'] ;
$emai = $_POST['email'];
$age = $_POST['age'] ;