评论会发送AJAX未捕获的语法错误:意外的标识符

时间:2019-03-09 22:13:00

标签: javascript ajax

请帮助我发现问题。尝试使用ajax发送评论时出现意外标识符 代码:

    function funcSuccess (data) {
    $("#comment_ajax").text(data);
}
function funcBefore (){
    $("#comment_ajax").text("Loading comment...");
}
$(document).ready(function(){
    $("#make_comment").bind("click", function () {
        event.preventDefault();
        $.ajax({
            let post = $("#c_post_id").val();
            let user = $("#c_user_id").val();
            let text = $("#c_text").val();
            url: "write_comment.php",
            type: "POST",
            data: {c_post_id: post, c_user_id:user, c_text:text},
            dataType: "html",
            beforeSend: funcBefore,
            success: funcSuccess
        });
    });
});

它显示在“ let post = $(“#c_post_id”)。val();”行中我做错了什么?

1 个答案:

答案 0 :(得分:0)

将代码更改为此,在您的ajax调用中将=替换为:,并将;替换为,

function funcSuccess (data) {
    $("#comment_ajax").text(data);
}

function funcBefore (){
    $("#comment_ajax").text("Loading comment...");
}

$(document).ready(function(){
    $("#make_comment").bind("click", function () {
        event.preventDefault();
        $.ajax({
            post: $("#c_post_id").val(),
            user: $("#c_user_id").val(),
            text: $("#c_text").val(),
            url: "write_comment.php",
            type: "POST",
            data: {c_post_id: post, c_user_id:user, c_text:text},
            dataType: "html",
            beforeSend: funcBefore,
            success: funcSuccess
        });
    });
});