0

下面是评论表单的脚本,它使用 ajax 发布到数据库后端。有一个回调来实时显示评论(没有页面刷新)。

回调处理由 json -string 函数(insert.php 的一部分)触发

echo json_encode(array('status'=>1,'html'=>$insertedComment->markup()));

但是 javascript 不响应它。这里有什么问题?

    /* Listening for the submit event of the form: */
    $('#addCommentForm').submit(function(e){

        e.preventDefault();


        /* Sending the form fileds to submit.php: */
        $.post('/comments/insert.php',$(this).serialize(),function(msg){



            if(msg.status){


                $('#body').val('');
            }
            else {

                /*
                /   If there were errors, loop through the
                /   msg.errors object and display them on the page
                /*/


            }
        },'json');

    });
4

0 回答 0