问题描述:

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");
    }
}
相关阅读:
Top