I have a small function (below) that takes a parameter to determine what to load. Is there a way I can make it so that the .load() kind of has an “else” or a fallback if it ecounters a 404?
function start(page,last){
$("#area").load("pages/"+page+".inc.php");
loading();
}
Thanks in advance 🙂
You can specify a function to be executed when the load completes.
Taken from the documentation:
Using your code it would look similar to this:
You can check the linked documentation for more details on possible return values and errors. In fact the demo on the bottom of the documentation shows dealing with a 404.
xhr.statusin the sample contains the error number404and thexhr.statusTextisNot Found.This would mean you can check for the specific number:
See DEMO