douren5898 2014-07-19 10:34
浏览 55
已采纳

parsererror / SyntaxError:意外的令牌<

I've searched a lot for this but the answers that I find doesn't work but I think that the problem is mine.

JavaScript:

$.ajax({
    type: 'POST',
    url: url,
    data: data,
    dataType: 'json',
    success: function(response) {
        if(response.status == true) {
            alert('ok');
        } else {
            alert('error');
        }
    },
    error: function(xhr, desc, err) {
        console.log(xhr);
        console.log("Details: " + desc + "
Error:" + err);
    }
});

PHP

if(User::addFavLater($id, $user, 'favs')) {
    $result = array("status" => true);
} else {
    $result = array("status" => false);
}

header('Content-type: application/json');
echo json_encode($result);

So, this is an excerpt of code that I have and I think can you realising. I want PHP to send a JSON response into JavaScript but this is not happening and JavaScript gives me this error:

parsererror / SyntaxError: Unexpected token <

I'm using the 2.1.1 version of JQuery.

P.S.: Sorry for my english.

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在matlab中如何进行三个参数的离散傅里叶逆变换(idft)
      • ¥15 遇到问题了,求解答!
      • ¥15 请问coppliasim eduUR5视觉抓取怎么实现仿真,
      • ¥30 JavaWeb实验(购物平台)
      • ¥15 八路抢答器倒计时设计时显示器不输出,只能显示0
      • ¥15 用C语言随机生成一个迷宫
      • ¥15 超多因素的正交方案设计
      • ¥15 Scratch~汽车小游戏
      • ¥30 OSGB转换为3dtiles
      • ¥25 用于Audio的芯片中“Audio Interface”和“Mode Control”是什么?