Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:24:07+00:00 2026-06-09T15:24:07+00:00

I have a small function (below) that takes a parameter to determine what to

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:24:09+00:00Added an answer on June 9, 2026 at 3:24 pm

    You can specify a function to be executed when the load completes.

    Taken from the documentation:

    $("#success").load("/not-here.php", function(response, status, xhr) {
      if (status == "error") {
        var msg = "Sorry but there was an error: ";
        $("#error").html(msg + xhr.status + " " + xhr.statusText);
      }
    });
    

    Using your code it would look similar to this:

    function start(page,last){
        $("#area").load("pages/"+page+".inc.php", function(response, status, xhr) {
            if (status == "error") {
                // don't load as an error occured,...do something else...
            }
            else{
                loading();
            };
        });
    }
    

    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.status in the sample contains the error number 404 and the xhr.statusText is Not Found.

    This would mean you can check for the specific number:

    function start(page,last){
        $("#area").load("pages/"+page+".inc.php", function(response, status, xhr) {
            if (status == "error" && xhr.status == ""404) {
                // a 404 occurred...
            }
            else{
                loading();
            };
        });
    }
    

    See DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small C# function that takes any generic SQLDataReader and converts it
I have a small function below that accepts associative arrays and I'm struggling to
I have a small function that runs on load and window resize.. but the
i have small function that running on condintion, if text box value is not
In an access database I have a small function that is called on startup
I have this small function that is causing me headaches on RHEL6, and I
I have several newbie questions concerning eigen. Below is a small function to illustrate
I have a small list of checkboxes (see below), and I noticed I can
I have a small javascript function which opens an url in a new tab:
i have build a small function whose work to get value in alert box

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.