簡體   English   中英

[],我將其作為json響應

[英][], I am getting this as a json response

我正在嘗試在成功函數中接受json,即這里的數據,我以[]的形式獲取數據,但在警報框中沒有獲取任何數據 有什么我想念的,任何人都可以幫忙。 提前致謝

    success: function (data) {
        $('#loader').hide();
        if (data != null) {
            alert('congratulations');
        }else{ 
            alert('no data');
        }
     }

嘗試將if (data != null)替換為if ((data || []).length)

如果您希望將數據作為數組,那么要測試其是否為空,請檢查其長度:

if (data && data.length > 0) {
    // ...
}

因為空數組[]不為null

編寫條件時,這些值被視為false:'',0,[],未定義,null

success: function (data) {
    $('#loader').hide();
    if (data == true)
        alert('congratulations');
    else
        alert('no data');
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM