Check if AJAX response data is empty/blank/null/undefined/0

前端 未结 5 754
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 23:57

What I have:

I have jQuery AJAX function that returns HTML after querying a database. Depending on the result of the query, the function will either return HTML co

5条回答
  •  春和景丽
    2020-12-23 00:06

    $.ajax({
        type:"POST",
        url: "",
        data: associated_buildsorprojects_form,
        success:function(data){
            // do console.log(data);
            console.log(data);
            // you'll find that what exactly inside data 
            // I do not prefer alter(data); now because, it does not 
            // completes requirement all the time 
            // After that you can easily put if condition that you do not want like
            // if(data != '')
            // if(data == null)
            // or whatever you want 
        },
        error: function(errorThrown){
            alert(errorThrown);
            alert("There is an error with AJAX!");
        }               
    });
    

提交回复
热议问题