The $.get() callback is a success function, so this will never run on error, you can either use $.ajax() for the full version, or rig up a global error event handler, whichever is more appropriate.
If you want to use $.ajax(), use the error callback, like this:
$.ajax({
url: nextHref,
success: function(data) {
//do something with good data, what comes after your if statement currently
},
error: function(xhr, status, error) {
alert("an error has occured: " + xhr.status + " " + xhr.statusText);
}
});
Or use the global event handler $().ajaxError() like this:
$(document).ajaxError(function(e, xhr) {
alert("an error has occured: " + xhr.status + " " + xhr.statusText);
});
Or, use $.ajaxSetup() to add an error handler for all requests, like this:
$.ajaxSetup({
error: function(xhr, status, error) {
alert("an error has occured: " + xhr.status + " " + xhr.statusText);
}
});