I am developing a comments box that will save the comment through a JQuery AJAX call.
JQuery
Here\'s the JQuery code for that (this works seamle
Try with the adequate JQuery function: submit() ^^ In my solution I suppose that your form has the id "comment_form". Works on all my sf2 projects:
$('#comment_form').submit(function(e) {
var url = $(this).attr("action");
$.ajax({
type: "POST",
url: url, // Or your url generator like Routing.generate('discussion_create')
data: $(this).serialize(),
dataType: "html",
success: function(msg){
alert("Success!");
}
});
return false;
});
The CSRF Field would normally be sent !
And don't forget to add the twig tag {{ form_rest(form) }} in your form template, that will generate all hidden field like CSRF.