I have an issue to making a function – load page without reloading, I have an problem that is “I want to show alert when link is 404 or not net connection is lost”. I know this code jqXHR.status == 0
to get net connection error or jqXHR.status !== 0
for 404 but I don’t know I don’t know how I implement this code with my existing code.
Please help me write this function.
$(function(){
$("a[rel='tab']").click(function(e){
pageurl = $(this).attr('href');
$.ajax({url:pageurl+'?rel=tab',success: function(data){
$('#containt').html(data);
}});
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
return false;
});
});
$(window).bind('popstate', function() {
$.ajax({url:location.pathname+'?rel=tab',success: function(data){
$('#containt').html(data);
}});
});
<a rel="tab" href="./404.php">Show me 404 ALert Pls</a>
2
Answers
Add a callback for an "error" event or "statusCode".
From the docs:
error
statusCode (default: {})
you could do it this way using error function