0

In my webapp I have a page where I use getJSON to get data from server. Firebug shows that it get's JSON from server just the way it is supposed to, but no data is shown. What could be the problem? Here is what my code looks like:

 $('#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');

}

Console shows

employee is undefined
[Break On This Error]   

$('#employeePic').attr('src', 'pics/' + employee.PIC);

This is the JSON response:

jQuery164008509381752724021_1336981793995({
    "key": [
        {
            "PIC": "Tuntematon",
            "NAME": "0",
            "TITLE": "0",
            "INFO": "0"
        }
    ]
})
2
  • Could you post your JSON please? Commented May 14, 2012 at 7:47
  • is there item property in data object? Commented May 14, 2012 at 7:47

1 Answer 1

2

You need to use this

var employee = data.key[0];
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. But I would like you to do some debug through console.log before posting :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.