JSON.parse:意外的数据结束错误

Dum*_*ock 4 jquery json

对于下面的代码,我收到此错误:

JSON.parse:意外的数据结束

at line var data = JSON.parse(json);

使用的代码是:

$(document).ready(function(){  
$("#button1").click(function(){
    $.post(
        'script_1.php',
        { id: $('input[name="id"]', '#myForm').val() },
        function(json) { 
            var data = JSON.parse(json);
            if (data.length === 0){
             alert('no data');   
            }
            else{
            $("input[name='title']").val(json.title);
                    $("input[name='age']").val(json.age); 
            }},
        "json"
    );
});
});
Run Code Online (Sandbox Code Playgroud)

后端的PHP是

$sql ="SELECT * FROM parent WHERE id = '$name'";       
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row) {
$row=  array('title' => $row['title'],'rno' => $row['reportno'],'url' =>      
$row['calc_url'], 'institution' => $row['institution']);
 echo json_encode($row);
 } else {
 echo json_encode(array());
 }
Run Code Online (Sandbox Code Playgroud)

这里错误的原因是什么?

Cra*_*ntz 9

当您"json"为回调指定data参数时,已经解析了.这里没有必要调用JSON.parse.