Check for $.ajax html result being empty
I want to know if the html returned in the success callback is empty:
var url = "..."
$.ajax({
url: url,
cache: false,
success: function(html){
if(html === ""){
开发者_运维百科 alert("empty");
}
}
});
But this does not work for me. Any ideas?
In your particular example, the success
handler would never get fired anyway.
You should bind an error handler
aswell:
var url = "..."
$.ajax({
url: url,
cache: false,
success: function(html){
alert('suc');
if(!$.trim(html).length){
alert("empty");
}
},
error: function() {
alert('err');
}
});
success: function(html){
if($.trim(html) === ""){
alert("empty");
}
}
精彩评论