i'm making a function that makes every form in my site to submit but "from behind", so the website is not redirected.
This is the code:
$('form').each(function(data){
var el = $(this);
$(el).submit(function(){
var action = el.attr('action');
$.post(action, function(){
console.log(action);
});
return false;
});
});
The "console.log" log without problems de URL, and the same URL have the data of the form. But the $.post function doesn't submit it.
Any Ideas?, this is in symfony2.
dont't forget to post your form data
i havr put an example with $.ajax
$(".yourform").submit(function(e){
e.preventDefault();
var data = $(this).serialize();
var action = $(this).attr('action');
$.ajax({
url: action,
type: "POST",
data: data,
success: function(result) {
//logic here
});
});
});