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.