I have a form and I want to save data through ajax jQuery post. If the save button is type="submit", it does not do any this just empty alert... I want to save data and remain on same form with refresh fields...
Here is what I have tried:
$("#saveNewContact").click(function () {
var name = $("#name").val();
var last_name = $("#last_name").val();
$.post("ajax_files/save_mydeals.php", {name: name, last_name: last_name},
success: function(msg){
alert(msg);
});
});
and here is my form
<form id="myForm" action="#" method="post">
<table id="table_1" class="form_table" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr><td>
<input name="name" id="name" value="" tabindex="5" readonly="" type="text">
<input name="name" id="name" value="" tabindex="5" readonly="" type="text">
<button type="submit" id="update" style="display:none;"
class="save_button saveHEX" name="Update"
value="Update Listing">Save Lead</button></td>
</tr>
</table>
</form>
button?$('#myForm').find('input').val('');do it inside your success function.