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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:24:34+00:00 2026-06-06T01:24:34+00:00

I am trying to fake synchronous JavaScript while doing an AJAX request. I have

  • 0

I am trying to fake synchronous JavaScript while doing an AJAX request.
I have an getPagePath(id) function that needs to get the page path of an page by giving it an page ID, it receives the data trough an web API. I thought this was going to be simple, just do an ajax request to the server and receive the page path. But what is happening: when requesting the page path my code keeps running and returns an empty var, after that the ajax call finishes, but to late.

I know my explaining is not much saying so here is my code:

var getPagePath = function() {

    // Function to check if this.pagePath is set.
    var pagePathReady = function() {
        console.log('PAGEPATH: CHECKING');
        if (this.pagePath && this.pagePath != null) {
            return true;
        } else {
            return false;
        }
    };

    if (!pagePathReady()) {
        // No pagePath defined so lets set it.
        this._setPagePath();

        while (!pagePathReady())
        {
            // Not yet defined, check again..

            // *** The problem ***
            // This while loop is running insanely fast making the browser crash.
            // How can I make this wile loop pause for 1 sec?
            // *******************

            console.log('PAGEPATH: NOT READY -> CHECK AGAIN');
        }

        // READY
        console.log('PAGEPATH: READY -> VALUE: ' + this.pagePath);
        return this.pagePath;
    } else {
        return this.pagePath;
    }
};

var _setPagePath = function() {
    if (!this.pagePathRequestFired) {
        this.pagePathRequestFired = true;
        // Fire request.
        system.url(
            this.getNodeId(), 
            function(url) {
                // Request ready, set pagePath.
                this.pagePath = url;
                this.pagePathRequestFired = false;
            }, 
            this
        );
    } else {
        // Call already running..
    }
};

I have set the problem in the more explaining comments.

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-06T01:24:36+00:00Added an answer on June 6, 2026 at 1:24 am

    You can make an ajax call synchronous if you really need to.

    xmlhttp.open("GET", "url", false);
    

    Note the 3rd param.

    But, I think you just need more practice in writing your code to work with the event/callback concept.

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

Sidebar

Related Questions

I'm trying to fake some information that are shown on the status bar (I'm
I have a SSAS cube in which there is a measure that needs to
I'm trying to test a function that takes input from stdin , which I'm
i'm trying to send fake keyboard input to an application that's running in a
I'm trying to get a fake movie website going for a University project. But
I'm trying to do a fake Ajax file upload with an iframe. When I
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to get a wildcard search to pick up on any text in org_name
trying to figure out why this is happening - I have an input text
Trying to change the selected text background color for an NSTextField (we have a

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.