When I call json object from php file it returns undefined. I can see all data writing alert(data)
but when I write alert(data.books) it returns undifined.
$JSON = '
{
"books": {
"book1": "firstbook",
"book2": "secondbook"
}
}
';
and I call it with jquery
jQuery('#login').live('submit',function(event) {
$.ajax({
url: 'lib/login.php',
type: 'POST',
dataType: 'json',
data: $('#login').serialize(),
success: function(data ) {
alert(' ' +data.books);
if(data.books.book1){
alert("OK");
}else
{
alert("error");
}
}
});
return false;
});
EDIT This is how it returns alert(data)
{
"books": {
"book1": "firstbook",
"book2": "secondbook"
}
}