jquery - undefined value for empty database record -
what best solution undefined
values being returned database when column empty. there way having
if (!(databasevalue == 'undefined') || !(databasevalue == null)) { console.log(databasevalue) } else { console.log('value empty') }
this ok if few values can empty if multiple values can empty check each value if undefined or not show result
update
$.ajax({ type: 'post', url: 'php', datatype: "json", data: { id: "id" }, success: function (data) { //check data undefined or not }, error: function (data) { console.log(data); } });
is there collective checking see data response undefined or need check each have if condition check if data empty or not
you need use &&
operator instead of ||
, undefined
should not in quotes
if (!(databasevalue == undefined) && !(databasevalue == null)) { console.log(databasevalue) } else { console.log('value empty'); }
however simplest solution should check truthy
condition, following condition check databasevalu
has value
if (databasevalu) { //!!databasevalu console.log(databasevalue) } else { console.log('value empty'); }
!!
double-negation used conversion of condition boolean
instead of truthy
Comments
Post a Comment