jQuery Ajax - Sending form data
Posted: 17 Apr 2015, 08:31
Hello
I have the following code to send form data to a php script, with jQuery Ajax, withouut reloading the page.
But, when I press the Submit button it opens the "page.php", and the alert() isn't displayed.
- How to make it work?
I have the following code to send form data to a php script, with jQuery Ajax, withouut reloading the page.
But, when I press the Submit button it opens the "page.php", and the alert() isn't displayed.
Code: Select all
<script>
$(document).ready(function(){
$('#form').submit(function(e) {
var form_data = $(this).serialize();
$.ajax({
type: 'POST',
url: '/page.php',
data: form_data,
success: function() {
alert('Message sent');
}
});
});
});
</script>