开发者

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");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜