javascript - Jquery 出错,提交按钮不显示
问题描述
我在我的 jquery 附加代码中找不到错误。除了最后一行之外,所有内容都在附加,这是在发布的评论/回复的底部放置一个表单和提交按钮。
问题似乎出在“profileformdiv”中。
profile.php:1 Uncaught SyntaxError: Unexpected token < in JSON at JSON.parse () at Object.success (getprofilecomment.js:36) at JSON.fireWith (jquery.js:3291) at Object.fireWith [as resolveWith] (jquery.js:3421) 在 XMLHttpRequest 完成 (jquery.js:9533)。(jquery.js:9785)
$(function(){
var userName = $("#username").val();
$.ajax({
method: "GET",
url: "api/getprofilecomment.php",
type: "json",
cache: false,
success: function(profileComment)
{
var profileComment = JSON.parse(profileComment);
for(var i = 0; i < profileComment.length; i++)
{
$("#usercommentdiv").append('<div class=' + '"' + 'profilecommentheader' + '"' + 'id=' + '"' + 'profilecommentheader' + '"' + 'name=' + '"' + 'profilecommentheader' + '"' + '>' + '</div>');
$("#usercommentdiv").append('<div class=' + '"' + 'profilecommentdiv' + '"' + 'id=' + "'" + profileComment[i].profile_comment_id + "'" + 'name=' + '"' + 'profilecommentdiv' + '"' + '>' + userName + ':' + profileComment[i].profile_comment + '</br>' + profileComment[i].time_added + '</div>');
$("#usercommentdiv").append('<div class=' + '"' + 'profileuseriddiv' + '"' + 'id=' + '"' + profileComment[i].profile_user_id + '"' + 'name=' + '"' + 'profileuserid' + '"' + '</div>');
$("#usercommentdiv").append('<div class=' + '"' + 'profileformdiv' + '"' + 'id=' + '"' + 'profileformdiv' + '"' + '>' + '<form type=' + "POST" + '>' + '<input type=' + "text" + 'id=' + "'" + "submit" + "'" + 'value=' + '"' + profileComment[i].profile_comment_id + '"' + '/>' + '<input type=' + "submit" + 'id=' + "submitreply" + 'onClick=' + "/api/postprofilereply.php" + 'value=' + "Reply" + "/>" + "</form>" + "</div>");
};
}
});
});
解决方案
推荐阅读
- javascript - 无法读取未定义 React 的属性“推送”
- c++ - 如何在 C++ 中不使用 pow 进行基本计算?
- webpack - Babel 构建导致赋值表达式中的左侧无效
- ruby-on-rails - 如何检测是否通过 Ruby on Rails 调用了 ruby 代码
- spring - Spring Security + MongoDB,请求一直得到401
- c# - 重复的元素名称'PropertyName'Mongodb驱动程序c#异常
- raft - Raft 问题 - 在领导者选举之间写入可用性
- mariadb - 将 MEDIAN 与 GROUP BY 一起使用
- swift - 如何彻底删除所有 Xcode 程序和缓存文件?
- javascript - 使用循环的节点 js 和 ejs