JQuery $ .ajax请求json响应

A JSON returned as response to this request is not recognized.

request = $.ajax({
        url: "form_handler.php",
        type: "post",
        dataType: "json",
        data: serializedData
});

The php code in form_handler.php which returns the response:

if ($success) {
    echo json_encode(array("success"=>"false"), JSON_PRETTY_PRINT); 
}
else
{
    echo json_encode(array("success"=>"true"), JSON_PRETTY_PRINT); 
}

And thus in:

request.done(data) 
{
    alert(data.success);     // error: cannot read property of 'success' of null 
}
查看全部
duanrenzou1619
duanrenzou1619
2014/08/20 13:31
  • json
  • php
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复