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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:59:16+00:00 2026-06-09T21:59:16+00:00

function ajax_request(destination_full_url) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp

  • 0
function ajax_request(destination_full_url) {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            alert("response: \n" + xmlhttp.responseText);
            return xmlhttp.responseText;

        }
    }

    xmlhttp.open("GET", destination_full_url, true);
    xmlhttp.send();
}



    function third_party_function(obj) {
       var response
       response = ajax_request("info.php?keyword=obj.value");
       alert(response);         
    }


<textarea onkeypress="third_party_function(this);"></textarea>

First comes off message box “underfined” one second after comes off message box with ajax request.

Question is why it runs alert(response); before finishing the previous step and how i make it wait untill ajax_request() function finished before going to next line?

  • 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-09T21:59:18+00:00Added an answer on June 9, 2026 at 9:59 pm

    because ajax is asynchronous and runs in background by default, you can make it synchronous by changing from

    xmlhttp.open(“GET”, destination_full_url, true);

    to

    xmlhttp.open(“GET”, destination_full_url, false);

    === update ===

    function ajax_request(destination_full_url, callback){
    .....
    xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                alert("response: \n" + xmlhttp.responseText);
               callback(xmlhttp.responseText);
    
            }
        }
    ...
    }
    
    ....
    
    
    function third_party_function(obj) {
           ajax_request("info.php?keyword=obj.value", function(response){alert(response) });
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following ajax function: function callAjax(request,callback) { if (window.XMLHttpRequest) {// code for
i have a script that i use to load some content: <script> $(.link_image).click(ajax_request); function
code speaks a thousand words page.php?id=123 <?php if(is_ajax()){// function that determines whether the request
I'm curious as to why this isn't working, here's the code: function Ajax(sUrl, fCallback)
i was wondering how/where to write a callback function after an ajax request is
I have a php function which returns JSON in response to a ajax request
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
I have a very simple ajax request: $.get(url, data) .done(function () { }) .fail(function
I am getting this error on a js function that sends an ajax request

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.