Reputation: 36
how to send a data for a multiple forms in a page a store a value of particular form through serialize form data.
$(function () {
$('.form').on('submit', function (e) {
console.log($(".form").serialize( )) ;
$.post({
type: 'post',
url: 'admin/sv_replycomment.php',
data: $(this).serialize(),
success: function (data) {
$('.form').trigger("reset");
$('#rep_response').html(data);
}
});
e.preventDefault();
});
});
Upvotes: 0
Views: 689
Reputation: 393
This is due to your all forms may have same class="form"
So to submit only one form with serialized data, you need to give a unique id to the form you want to submit and serialize()
data
For example:
<form id="type1" class="form">
...
</form>
And now your request should be like
$(function () {
$('#type1').on('submit', function (e) {
$.post({
type: 'post',
url: 'admin/sv_replycomment.php',
data: $(this).serialize(),
success: function (data) {
$('#type1').trigger("reset");
$('#rep_response').html(data);
}
});
e.preventDefault();
});
});
I think this will solve your problem because using class selector will work for all form which have same class
Upvotes: 1
Reputation: 413
Modify your Code To post all fields data from the FORM to PHP
//Ajmal Praveen
$("#submit").click(function() {
$.ajax({
data: $("form").serialize(),
...rest
});
});
Upvotes: 0