Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to display the failure response of Jquery.get() using Jquery.when(). On the below code, .done() is called perfectly after successfull load. but fail() is not called if the .get() request fails.

fileName = "page1.html";
$.when( $.get( "assets/"+fileName , function( data ) {
    xhtmlsrc = data;
}))
.done(function(){
    $( "#dynamic_content" ).html(xhtmlsrc);
    hidepreloader();
})
.fail(function(){ 
    $( "#dynamic_content" ).html('ERROR: File not found');
    hidepreloader();
});

What is wrong here? Any suggestions would be appreciated.

share|improve this question
 
Seems to work as you expected: jsfiddle.net/P59u5 .How did you test that .get() request fails ? send 404 from assets/page1.html or something else? –  ymonad 1 hour ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.