1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
<form id="my_form" method="post" action="process_form.php">
<input type="text" name="title">
<textarea name="content"></textarea>
<button type="submit">OK</button>
</form>
et :
$(function () {
$('#my_form').on('submit', function (e) {
// On empêche le navigateur de soumettre le formulaire
e.preventDefault();
var $form = $(this);
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
data: $form.serialize(),
success: function (response) {
// La réponse du serveur
}
});
});
}); |
Partager