jquery, send a form by staying on the same page
ajax, forms, jquery
Solution
Do this way:-
$(document).on('submit', '.myForm', function(e) {
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: $(this).serialize(),
success: function(html) {
alert('ok');
}
});
e.preventDefault();
});
Problem
I want to send a form without leaving my current page, so I'm using: ``` $('.myForm').on('submit', function(){ $.ajax({ url: $(this).attr('action'), type: $(this).attr('method'), data: $(this).serialize(), success: function(html) { alert('ok'); } }); return false; }); ``` but it doesn't work... any idea please?