jQuery AJAX form data serialize using PHP
ajax, forms, jquery, php
Solution
Try this
$(document).ready(function(){
var form=$("#myForm");
$("#smt").click(function(){
$.ajax({
type:"POST",
url:form.attr("action"),
data:$("#myForm input").serialize(),//only input
success: function(response){
console.log(response);
}
});
});
});
Problem
I am stuck in my code, I need to send data from the form to the check.php page and then process it. This is my code: The AJAX part: ``` <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function(){ var form=$("#myForm"); $("#smt").click(function(){ $.ajax({ type:"POST", url:form.attr("action"), data:form.serialize(), success: function(response){ console.log(response); } }); }); }); </script> ``` The form: ``` <form action="check.php" method="post" name="myForm" id="myForm"> <input type="text" name="user" id="user" /> <input type="text" name="pass" id="pass" /> <input type="button" name="smt" value="Submit" id="smt" /> </form> <div id="err"></div> ``` the php part: ``` $user=$_POST['user']; $pass=$_POST['pass']; if($user=="tony") { echo "HI ".$user; } else { echo "I dont know you."; } ```