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 8050025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:57:07+00:00 2026-06-05T06:57:07+00:00

I decided to contain this code into an object to separate it out from

  • 0

I decided to contain this code into an object to separate it out from the areas it will be applied. Any advice here is really appreciated:

appConfig.loadElement and appConfig.cerrorElement are these HTML elements:

<div id="loading" style="display:none;">Loading...</div>
<div id="cerror" style="display:none;">Connection Error.</div>


var loadingTimeoutInstance = null, cerrorTimeoutInstance = null,
    requestObj = {
    reset: function() {
        $(appConfig.loadElement).hide();
        $(appConfig.cerrorElement).hide();
        clearTimeout(loadingTimeoutInstance);
        clearTimeout(cerrorTimeoutInstance);
    },
    initiate: function() {
        loadingTimeoutInstance = setTimeout(requestObj.timeout, appConfig.loadingDelayMS);
    },
    timeout: function () {
        clearTimeout(loadingTimeoutInstance);
        $(appConfig.loadElement).show();
        cerrorTimeoutInstance = setTimeout(requestObj.cerror, appConfig.cerrorDelayMS);
    },
    cerror: function () {
        clearTimeout(cerrorTimeoutInstance);
        $(appConfig.loadElement).hide();
        $(appConfig.cerrorElement).show();
    }
}

An implementation is like so:

When an asynchronous request is made:

requestObj.reset();
requestObj.initiate();

After the response is returned:

requestObj.reset();

The problems I have identified are mainly in requestObj.reset():
– Why hide elements if they are already hidden?
– Can’t clear the timeout vars (loadingTimeoutInstance and cerrorTimeoutInstance) if they are not set as timeouts yet – this causes it not to work.

  • 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-05T06:57:09+00:00Added an answer on June 5, 2026 at 6:57 am

    You don’t actually need to check if it’s of a certain type… just that it is.

    if(cerrorTimeoutInstance) clearTimeout(cerrorTimeoutInstance);

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

Sidebar

Related Questions

From the code sample of this question , I added a string property to
I decided to learn concurrency and wanted to find out in how many ways
My boss decided recently to try out an outsourcing group for increased capacity as
My task Create a UserControl which should be able to contain any visual child
I have decided to create a new table in my database that will be
I want to build a service that will pass the data read from the
This is my first time posting on stackoverflow so bear with me. I decided
I've looked a lot into this, but I can only seem to get webView
I have this route: {controller}/{id}/{action} Because I think it makes more sense from RESTful
Like many people, I have several SVN repositories that contains several projects. I've decided

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.