jquery and ajax basic is well known to everyone. I am explaining basic example of submitting a for using ajax in serialize form
Her is xample:-
We have basic form
<form id=”simpleFormId” name=”simpleFormName” method=”post” enctype=”multipart/form-data” autocomplete=”off” >
<input type=”text” name=”firstName” id=”firstName” placeholder=”First Name” value=”” >
<input type=”text” name=”lastName” id=”lastName” placeholder=”Last Name” value=”” >
<button btntype=”save” type=”button” id=”user_profile_Submit”>Save</button>
</form>
Keep in mind you have to include basic jquery library to run jquery and ajax. I am assuming you already added them in headr part.
Now on other side at script part, I am adding onclick function on based on submit button Id which is “user_profile_Submit”
<script>
$(‘#user_profile_Submit’).click(function(){
$.ajax({
type: “POST”,
url: “your_php_file_url_for_code_part.php”,
data: $(‘form#simpleFormId’).serialize(),
success: function(resultmsg) {
if(resultmsg==”success”){
alert(“yes it’s done!”);
}else{
aler(“it’s failed!!”);
}
}
});
});
</script>
In above example data: $(‘form#simpleFormId’).serialize()
is doing your form in serialize. I am using form id “simpleFormId” to point particular form.
It’s done. It’s basic example.
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016