突然未捕获的SyntaxError:意外的令牌<在位置0的JSON中

时间:2017-05-29 16:19:09

标签: jquery html json

我得到一个Uncaught SyntaxError:意外的令牌<在我的代码中的位置0错误的JSON中。它之前工作正常,突然开始给我这个错误。

userHome:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at Object.success (userHome:28)
at fire (jquery-3.2.1.js:3317)
at Object.fireWith [as resolveWith] (jquery-3.2.1.js:3447)
at done (jquery-3.2.1.js:9272)
at XMLHttpRequest.<anonymous> (jquery-3.2.1.js:9514)

,代码是:

<script>
$(function() {
  $.ajax({
    url: '/getWish',
    type: 'GET',
    success: function(res) {
      var div = $('<div>')
        .attr('class', 'list-group')
        .append($('<a>')
          .attr('class', 'list-group-item active')
          .append($('<h4>')
            .attr('class', 'list-group-item-heading'),
            $('<p>')
            .attr('class', 'list-group-item-text')));

      var wishObj = JSON.parse(res);
      var wish = '';

      $.each(wishObj, function(index, value) {
        wish = $(div).clone();
        $(wish).find('h4').text(value.Title);
        $(wish).find('p').text(value.Description);
        $('.jumbotron').append(wish);
      });
    },
    error: function(error) {
      console.log(error);
    }
  });
});
</script>

0 个答案:

没有答案