2010-08-24 43 views
2

我创建这个脚本,从JSON加载数据,这是编码在PHP文件(JSON是有效的)。jQuery JSON回调说'未定义'

当点击一个div,它应该显示从jQuery,这都是在这里完成的数据:

function quickView(pid) { 
    $.getJSON('project.php', { id: pid, view: 'true' }, function(data) { 
     $('#view-' + pid).html('<p>' + data.name + '</p>' 
     + '<p>' + data.deadline + '</p>'); 
    }); 
} 

的HTML:

<a href="project.php?id=1"> 
    <div class="row-null"> 
     <p>An example project</p> 
    </div> 
</a> 
<div class="row-null quick-view" id="view-1" title="Quick View" onclick="quickView(1);"> 
    <p><img src="img/pixel.png" height="5" width="9" alt="" /></p> 
</div> 

然而,当我点击它,它打开并说不定......

输出时JSON:

[ 
    { 
     "name": "Another example project", 
     "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", 
     "deadline": "Tuesday 24th August 2010" 
    } 
] 

什么问题?

回答

2

您的服务器正在返回一个数组,因此您需要data [0] .name。

+0

一个小小的修复><但是,谢谢! – MacMac 2010-08-24 23:48:40