jQuery Ajaz to check if returned data object is empty
In one of my jQuery Ajax Request ,I need to check wehter quary return empty results.
$.post("php/socialbookmark-post.php", {bookmarkID: $(this).val()},function(data)
{
if(data != "") alert(data);
});
data !== 'undefined' && data !== '' not worked Properly and Stack OverFlow also not given
good answer.
data !== 'undefined' && data !== '' not worked Properly and Stack OverFlow also not given
good answer.
I observed, If empty data set returned , the full block will not executed.
I observed, If empty data set returned , the full block will not executed.
http://stackoverflow.com/questions/2589558/jquery-to-check-if-returned-data-object-is-empty
http://stackoverflow.com/questions/2589558/jquery-to-check-if-returned-data-object-is-empty
But refffering to jQuery I able to come up with solid answer.
But refffering to jQuery I able to come up with solid answer.
http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.ajax/
By defult we inherit the sucess method (done ) and if empty data set returned it will go (fail).
By defult we inherit the sucess method (done ) and if empty data set returned it will go (fail).
$.post("./testURL" function (o) {
//alert(o.length);
if (o.ERROR == null) {
$.each(o, function (key, value1) {
//defult code
})
}
}, 'json') .done(function(o) {
//alert( "second success"+o );
})
.fail(function(o) {
//return empty set will fire this one
console.log('error result: ' + JSON.stringify(o));
$.each(o, function (key, value1) {
console.log(value1);
});
});
$.post("./testURL" function (o) {
//alert(o.length);
if (o.ERROR == null) {
$.each(o, function (key, value1) {
//defult code
})
}
}, 'json') .done(function(o) {
//alert( "second success"+o );
})
.fail(function(o) {
//return empty set will fire this one
console.log('error result: ' + JSON.stringify(o));
$.each(o, function (key, value1) {
console.log(value1);
});
});
Comments
Post a Comment