使用ajax和jquery发布评论

我想在用户评论后显示发布的评论。 只是将其添加到facebook下面。

我有这个:

// Interceptamos el evento submit $('#CommentAddForm').submit(function() { alert("entro"); alert($(this).attr('action')); // Enviamos el formulario usando AJAX $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), // Mostramos un mensaje con la respuesta de PHP success: function(data) { $('#result').html(//????????????); } }); return false; }); 

但我不知道它是如何工作的,我不知道我应该在$('#result').html(//????????????);行写什么$('#result').html(//????????????);

变量URL包含在DB中插入注释的路由。 它运作良好。 任何的想法? 谢谢。

顺便说一句,我一直在阅读这个答案: Ajax / jQuery评论系统但我仍然没有得到它。

好ı完成它,它的工作正常。 当你提交时,它会将你的评论附加到评论框中,就像facebook一样。

像这样改变你的代码:

 var comment=$('.comment').val(); // your comment text box $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), // Mostramos un mensaje con la respuesta de PHP success: function(data) { $('.commentbox').append(""+comment); // list of comments. its inserting your last comment at the end of line. } });