Check if AJAX response data is empty/blank/null/undefined/0
The following correct answer was provided in the comment section of the question by Felix Kling:
if (!$.trim(data)){
alert("What follows is blank: " + data);
}
else{
alert("What follows is not blank: " + data);
}
//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