在我的 webapp 中,我有一个页面,我使用 getJSON 从服务器获取数据。Firebug 显示它以应有的方式从服务器获取 JSON,但未显示任何数据。可能是什么问题呢?这是我的代码的样子:
$('#detailsPage').live('pageshow', function(event) {
var id = getUrlVars()["id"];
$.getJSON(serviceURL + 'getemployee.php?id='+id+'&callback=?', displayEmployee);
});
function displayEmployee(data) {
var employee = data.item;
$('#employeePic').attr('src', 'pics/' + employee.PIC);
$('#fullName').text(employee.NAME);
$('#employeeTitle').text(employee.TITLE);
$('#lisatieto').text(employee.INFO);
if (employee.puhelin_nro) {
$('#actionList').append('<li><a href="tel:' + employee.puhelin_nro + '"><h3>Soita puhelimeen</h3></a></li>');
$('#actionList').append('<li><a href="sms:' + employee.puhelin_nro + '"><h3>SMS</h3></a></li>');
}
$('#actionList').listview('refresh');
}
控制台显示
employee is undefined
[Break On This Error]
$('#employeePic').attr('src', 'pics/' + employee.PIC);
这是 JSON 响应:
jQuery164008509381752724021_1336981793995({
"key": [
{
"PIC": "Tuntematon",
"NAME": "0",
"TITLE": "0",
"INFO": "0"
}
]
})