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

前端 未结 5 763
伪装坚强ぢ
伪装坚强ぢ 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:27

    //if(data="undefined"){
    

    This is an assignment statement, not a comparison. Also, "undefined" is a string, it's a property. Checking it is like this: if (data === undefined) (no quotes, otherwise it's a string value)

    If it's not defined, you may be returning an empty string. You could try checking for a falsy value like if (!data) as well

提交回复
热议问题