首页 > 解决方案 > 评论发送 AJAX Uncaught SyntaxError: Unexpected identifier

问题描述

请帮我找出问题所在。尝试使用 ajax 发送评论时,我得到了 Unexpected identifier 代码:

    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();" 行的行上 我做错了什么?

标签: javascriptajax

解决方案


将您的代码更改为此,在您的 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
        });
    });
});

推荐阅读