Hello Reader's
If you want to make your form reusable and set the action dynamic via ajax, Then you can make the ajax call like in the example below:-
<form id = 'idForm'>
...
</form>
and the script will go like this
<script>
// this is the id of the form
$("#idForm").submit(function(e) {
var url = "action.php"; // the script where you want to put action.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
</script>
0 Comment(s)