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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:13:40+00:00 2026-05-24T11:13:40+00:00

Here is a program that calls ajax to read a value from the header

  • 0

Here is a program that calls ajax to read a value from the header of a http response and set a variable called _ecpop and use that for later operations…

So I defined a variable globally called _ecpop as

var _ecpop="";

and then here is the ajax call code:

if (typeof XMLHttpRequest != "undefined") {
    _ec_req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    _ec_req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    // make the request
    _ec_req.open("GET", requestString, true);
    // function to deal with response
    _ec_req.onreadystatechange = function()  {
    if (_ec_req.readyState==4)
        {
        if (_ec_req.status==200)
            {
            var respHeaders = _ec_req.getAllResponseHeaders();
            // strip out unnecessary headers
            respHeaders = respHeaders.replace (/\n/g,"|X|");
            var beg = respHeaders.indexOf("ECAcc (");
            _ecpop = respHeaders.substring(beg+7,beg+10);
            //make an if statement here...
            console.log(_ecpop);

            }

        }
    }
    console.log(_ecpop);

and the rest of the code uses _ecpop.

The problem is the browser executes the rest of the code with _ecpop=””. i.e. first the second console.log(_ecpop); returns empty and then the first console.log(_ecpop); returns the correct value.

Is there anybody who knows how I can get around it? it is so irritating …

Thanks,

Amir.

  • 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-24T11:13:42+00:00Added an answer on May 24, 2026 at 11:13 am

    AJAX (an acronym for Asyncronous Javascript And XML) is inherently asynchronous. That means that it begins executing when the Javascript engine encounters it in a script, but the rest of the script continues processing without waiting for the AJAX call to complete.

    You can circumvent this behavior by instructing your AJAX call to operate synchronously:

    _ec_req.open("GET", requestString, false);
    

    Setting false as third parameter of open() will provide your requested behavior.

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

Sidebar

Related Questions

I have a C++ program called myArchive that calls routines from a static C
How can I set an environment variable in WSH jscript file that calls another
I would like to write a C++ program that calls the mvndst_() subroutine from
Here is a C# program that tries Marshal.SizeOf on a few different types: using
Here is a special Haskell program which outputs a Python program that outputs a
I've got a program that worked until recently. The offending code is shown here:
Here's a piece of code that takes most time in my program, according to
first question here. I'm developing a program in C# (.NET 3.5) that displays files
I have a program that makes some hefty calls to the database and then
I am programming a client program that calls a webmethod but when I get

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.