企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 5、评论功能 1、对用户角色进行判断 ![](https://img.kancloud.cn/4d/b0/4db01e9a7ecbfe37469c01a8b992dfd7_865x729.png) 2、获取网站评论功能是否开启 ~~~ //评论是否经过人工审核 var revi ew; //获取网站的配置信息 $. ajax({ type : get', url:' /settings' , success: function (response) { review = response.review //判断管理员是否开启的评论功能 if (response。comment) { //管理员开启了评论功能渲染评论模板 var html = template(' commentTpl');| $( ' #comment' )。html(html); } }) ~~~ 3、创建评论 ~~~ //当评论表单发生提交行为的时候 $(' #comment' )。on( ' submit ' ,'form', function () { //获取用户输入的评论内容 var content = $(this). find( 'textarea').val(); //代表评论的状态 var state; if (review) { I //要经过人工审核 state = 0; }else { //不需要经过人工审核 state = 1; } //向服务器端发送请求执行添加评论操作 $ ,ajax({ type:'get', url :' / comments ', data: { content: content, post: postId, state: state }, success: function () { alert('评论成功') location . reload(); }, error: function () { alert('评论失败') } //阻止表单默认提交行为 return false; }) ~~~