i have my code JS code:
$.getJSON('getMessageDetails.php', function (json) {
//alert(json.length);
//$("#subject1").html(json[0].subject);
//$("#unique_code1").html(json[0].unique_code);
$("#msg_id").html(json[0].id);
$("#subject").html(json[0].subject);
$("#unique_code").html(json[0].unique_code);
if (json.length) > 0)
{
alert(json[0].length);
} 开发者_运维百科
});
how should i test if json is not null or index is > 0?? the if is not executing.. the alert does not come up please help thank you
you have unnecessary ) (one opening and two closing)
if (json.length > 0)
{
alert(json[0].length);
}
is correct
so finally
$.getJSON('getMessageDetails.php', function (json) {
//alert(json.length);
//$("#subject1").html(json[0].subject);
//$("#unique_code1").html(json[0].unique_code);
$("#msg_id").html(json[0].id);
$("#subject").html(json[0].subject);
$("#unique_code").html(json[0].unique_code);
if (json.length > 0)
{
alert(json[0].length);
}
});
精彩评论