首页 > 解决方案 > 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>");
    };
}

});
});

标签: javascriptjquery

解决方案


推荐阅读