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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:16:12+00:00 2026-05-24T18:16:12+00:00

I have a question about sync requests. Background: I need to get the userID

  • 0

I have a question about sync requests.

Background: I need to get the userID of the user immediately before checkout. If userID is null or zero I will force the user to login. I decided to use the synchronous request. I understand the difference between async and sync requests. However I don’t understand why the first code below does not work, but the second does.

...
UserId = GetUserId();
...

function GetUserId()
{
  var jsonRequest = new Request({url: myurl, async: false, onComplete: function(result) {return result;}}).get();
}

When I use the code above, I get UserId = undefined. However it works when I use the code below

...
UserId = GetUserId();
...

function GetUserId()
{
  var resultreturned;
  var jsonRequest = new Request({url: myurl, async: false, onComplete: function(result) {resultreturned = result;}}).get();
  return resultreturned;
}

It seems to me that in the first code, the processing does not stop even though I used the async:false. In the second code it works.

Does anyone know why?

In addition, is there a way to access the returned id without using the var resultreturned? Can I access the return using something like

return jsonRequest.value or jsonRequest.result or something else?

Thank you.

  • 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-05-24T18:16:13+00:00Added an answer on May 24, 2026 at 6:16 pm

    The first version of GetUserId doesn’t return anything. Simple as that. That the anonymous function passed as the completion handler returns something doesn’t matter; its return value is passed to some internal mootools function and is ignored.

    As for accessing the result, the base XMLHttpRequest object should be accessible as the xhr property of the Request object (though this doesn’t appear to be part of Request’s public interface), and the response (in turn) is accessible as the responseText property of the XHR object. In short, try:

    jsonRequest.xhr.responseText
    

    However, this shouldn’t be necessary. Any synchronous request can be turned into an asynchronous request by passing along a callback to run when the request completes. The function you pass as the onComplete argument is an example of this. This has the technical name of “continuation passing” (a “continuation” is, somewhat informally, “the rest of the calculation, from a give point forward”).

    Forget about call stacks for a moment. Pretend the return statement as just another function. This return function is a continuation; when it’s called, the rest of the calculation happens. The first step in switching to asynchronous calls is to have your GetUserId function call the continuation passed in instead of special return continuation.

    function GetUserId(succeed, fail)
    {
      var resultreturned;
      var jsonRequest = new Request({url: myurl, async: false, onSuccess: function(result) {resultreturned = result;}, onFailure: fail}).get();
      succeed(resultreturned);
    }
    

    To finish the switch, pass the continuation on to Request rather than invoking it in GetUserId, and make the request asynchronous.

    function GetUserId(succeed, fail)
    {
      new Request({url: myurl, onSuccess: succeed, onFailure: fail}).get();
    }
    
    ...
    function checkoutOrLogin(userId, responseXML) {
        if (userId) {
            /* continue checkout */
        } else {
            /* display login form */
        }
    }
    GetUserId(checkoutOrLogin, function(xhr) {/* display error message */});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a newbie question about Git: I need to move back and forth
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about how to deploy WPF application into a PC without
I have a question about using os.execvp in Python. I have the following bit
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about this question . I posted a reply there but

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.