用ajax和jquery发布评论 [英] Posting comment with ajax and jquery

查看:163
本文介绍了用ajax和jquery发布评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在用户发表评论后显示发布的评论.只是要像在Facebook上一样将其添加到所有这些对象下.

I want to display the posted comment once the user comments. Just to add it under all of them as facebook does.

我有这个:

 // 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(//????????????);

But i don't know very well how it works and i dont know what should i write in the line $('#result').html(//????????????);

变量URL包含在数据库中插入注释的路由.而且效果很好. 任何的想法?谢谢.

The variable URL contains the route which inserts the comment in the DB. And it works well. Any idea? Thanks.

顺便说一句,我一直在读这个答案: Ajax/jQuery评论系统 但是我还是不明白.

By the way, i have been reading this answer: Ajax/jQuery Comment System But i still don't get it.

推荐答案

好的,我完成了它,并且工作正常.当您提交时,它会像Facebook一样将您的评论添加到评论框.

ok ı finished it and its work fine. when you submit, its appending your comment to commentbox as facebook does.

像这样更改您的代码:

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("</br>"+comment); // list of comments. its inserting your last comment at the end of line.

           }
        });   

这篇关于用ajax和jquery发布评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆