Reset /Delete input field value after sending with Ajax
Posted: 18 Apr 2015, 06:48
Hello,
I have the following code that sends form data with Ajax to a php script. It works, but after the form data is sent, the value added in the input field remains.
How can I reset (or delete) the value of the input field after the form data have been sent with Ajax?
I have the following code that sends form data with Ajax to a php script. It works, but after the form data is sent, the value added in the input field remains.
Code: Select all
<form action="/page.php" method="post" id="form">
<input type="text" name="phone" required="required" />
<input type="submit" name="sbmt" value="Send" />
</form>
<script>
$(document).ready(function(){
$('#form').submit(function(e) {
e.preventDefault(); // STOP default action
e.unbind(); // to stop multiple form submit
var form_data = $(this).serialize(); // get form data into a string with pairs: name=value
$.ajax({
type: 'POST',
url: '/page.php',
data: form_data,
success: function() {
alert('Message sent');
}
});
});
});
</script>