开发者

why is (json[0].length) > 0) not working?

开发者 https://www.devze.com 2023-03-31 18:36 出处:网络
i have my code JS code: $.getJSON(\'getMessageDetails.php\', function (json) { //alert(json.length); //$(\"#subject1\").html(json[0].subject);

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);
            }      
        }); 
0

精彩评论

暂无评论...
验证码 换一张
取 消