if(data && data != “”) alert(data); data will be null in your case, and null != “” , so the if is passing.
Read moreHow check object is null or not in jQuery?
you can check your JavaScript OR jQuery object is empty or not, because we need to check many place our jQuery object is empty, null or undefined etc., So usually, we can check using $. isEmptyObject() as i explained as under.9 Oca 2016
Read moreHow check string is empty or null in jQuery?
isStringNullOrEmpty(val) || val. replace(/\s/g, “”) === ”; } , //If string is null or empty then return Null or else original value nullIfStringNullOrEmpty: function (val) { if (this. isStringNullOrEmpty(val)) { return null; } return val; } }, Utilize this helpers to achieve that.
Read moreIs object empty jQuery?
isEmptyObject( object ) Returns: Boolean. Description: Check to see if an object is empty (contains no enumerable properties).
Read more