javascript - 评论发送 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();" 行的行上 我做错了什么?
解决方案
将您的代码更改为此,在您的 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
});
});
});
推荐阅读
- ffmpeg - FFmpeg 幻灯片 concat 仅输出最后一张图片
- python - 其他测试用例的三角形质心问题失败
- flutter - 如何从 Flutter Code for Flutter-Web 中设置 index.html 中定义的 js 属性
- python - 如何在多对多字段中按项目过滤?
- python - 价格不加起来
- python - 在 pandas 中处理大量的大数据文件
- javascript - Javascript:为数组中的每个对象添加一个唯一的ID
- javascript - javascript中的字符串到html的转换
- node.js - OAuth2:如何将会话数据传递到前端?
- javascript - Web API 路由对 2 个不同的调用给出相同的响应