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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:42:25+00:00 2026-06-04T00:42:25+00:00

I have an XMLHttpRequest that insert a lot of data to a MySQL database

  • 0

I have an XMLHttpRequest that insert a lot of data to a MySQL database and takes 5-10 seconds. Here’s The code of the request:

function sendRequest(url, params, divToChange)
{
   // code for IE7+, Firefox, Chrome, Opera, Safari
   if (window.XMLHttpRequest)
   {
       var httpRequest = new XMLHttpRequest();
   }      
   else // code for IE6, IE5
   {
       var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
   }

   // Stage 3 - open the request and prepare variables for the PHP method being  
      activated on server side//
   httpRequest.open("POST", url, true); 

   //Set request headers for POST command//
   httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   httpRequest.setRequestHeader("Content-length", params.length);
   httpRequest.setRequestHeader("Connection", "close");

   httpRequest.onreadystatechange=function()
   {
       if(httpRequest.readyState==3)
       {     
           document.getElementById(divToChange).innerHTML='please wait';
       }
       if(httpRequest.readyState==4 && httpRequest.status==200)
       {
           document.getElementById(divToChange).innerHTML=httpRequest.responseText;
       }
   }

   httpRequest.send(params); // Stage 4 - sending the request to the server//

   //end when the server will responde we will execute the        
   "document.getElementById("txtHint").innerHTML=xmlhttp.responseText;" //

}

//Calling the request with this function//
function createEventList() 
{   

   var url = "grid-update_event_list.php";
   var params = "firstLoad=1";

   //Create the httpRequest and send it to the server//
   sendRequest(url,params, "eventsList");  
}

And this is defined in my html to get the responses text:

<p>Events List Status: <b id='eventsList'>  </b></p>

I cant understand 2 behaviors in my browser:

1- The “please wait” text never shows on the browser. When I’ve added an alert(httpRequest.readyState) to test what’s happening, I got popup with “3” as expected, but I’ve seen that immediately after readyState==3 it goes to readyState==4. It seems like they happen simultaneously. I do see the text returned in the httpRequest.responseText; of readyState==4.

2- I cant navigate to another page after sending the request, The current page is responsive (I can change comboboxes) but when I try to navigate to another link the browser waits to readyState==4 and only then It continues to the link. I cant understand that either, because the request defined as asynchronous = true.

Am I doing something wrong that causing these 2 behaviors ? thanks.

  • 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-04T00:42:26+00:00Added an answer on June 4, 2026 at 12:42 am

    1.- you need to understand the readystates of an ajax call. There are 5 different ready states. For more information look at this link:

    ReadyStates

    so you could use a different readystate ( i would use 1 or 2) to display the dialog at the beginning of the request. Otherwise just change the div BEFORE you send the httpRequest.

    2.- Even if ajax calls are asyncronous, they are sequential. That is, if you send a request, you cannot send another request until you have received the response of that request. Changing pages is another request/response cycle, so you won’t be able to change page until you have received the response of the first request.

    Hope this helps…

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

Sidebar

Related Questions

I have a code that XMLHttpRequest. It's a object to send request to server
I have a weird issue that is probably simple here is the code js
I have a javascript that fetches data from mysql and displays it in my
I have a javascript function that loads 100 div's from a xmlhttprequest function. I
i have this problem that i can't solve for days now...here is my code.
I have a XMLHTTPRequest that contains SOAP message. I want to add guid that
I have a web application that adds contextual information to XmlHttpRequest objects using the
I have a javascript that does this (http is your XMLHttpRequest object) var r
I am developing java web services (JAX-WS) to insert data into mysql DB and
I have a function that issues an AJAX call (via jQuery). In the complete

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.