意外的令牌<使用ajax和codeigniter时

时间:2015-02-11 14:05:24

标签: ajax

我浪费了我的一天寻找解决方案。 这是我的jquery函数 这就是我得到的错误“Uncaught SyntaxError:Unexpected token<” 请帮忙 感谢

$('#post_comment').click(function(){
  var question_id=$('#question_id').val();
  var comment=$('#comment').val();
  var user_id=$('#user_id').val();

  $.ajax({
    type : 'POST',
    url : 'questions/update_question',
    data : {question_id:question_id,comment:comment,user_id:user_id},

    success:function(response) {
      $('#comment_textarea').toggleClass("hidden");
      // alert(response);
      var result=JSON.parse(response);
      var div1="<div class='row comment_rows>";
      var div2="<div class='col-sm-9 comment_description_column'></div>";
      var div3="<div class='col-sm-3 comment_description_userinfo'></div></div>";

      $('.comment_rows:last').append(div1,div2,div3);
      $('.comment_description_column:last').text(result.comment_description);
      $('.comment_description_userinfo:last').text(result.user_id);			

    },
    error: function (xhr, ajaxOptions, thrownError) {
      console.log("Status: " + xhr.status);
      console.log("Message: " + thrownError);
    }
  });
});

1 个答案:

答案 0 :(得分:1)

在你的ajax中你忘了用==&gt;关闭一个班级'

$('#post_comment').click(function(){
  var question_id=$('#question_id').val();
  var comment=$('#comment').val();
  var user_id=$('#user_id').val();

  $.ajax({
    type : 'POST',
    url : 'questions/update_question',
    data : {question_id:question_id,comment:comment,user_id:user_id},

    success:function(response) {
      $('#comment_textarea').toggleClass("hidden");
      // alert(response);
      var result=JSON.parse(response);
      var div1="<div class='row comment_rows>";
      // you forget to close the class -----^  

      var div2="<div class='col-sm-9 comment_description_column'></div>";
      var div3="<div class='col-sm-3 comment_description_userinfo'></div></div>";

      $('.comment_rows:last').append(div1,div2,div3);
      $('.comment_description_column:last').text(result.comment_description);
      $('.comment_description_userinfo:last').text(result.user_id);         

    },
    error: function (xhr, ajaxOptions, thrownError) {
      console.log("Status: " + xhr.status);
      console.log("Message: " + thrownError);
    }
  });
});