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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:18:04+00:00 2026-06-11T21:18:04+00:00

In my web application, what the user does on the page have to be

  • 0

In my web application, what the user does on the page have to be sent my database, so I have the latest changes saved.

I just call the function with the request here when the user close the page:

window.onbeforeunload = sendData;

But where the problems come up is when I send data every 10 second. I do send my requests sync and not async (or it would not be sent onbeforeunload). The problem is that this adds delays to the user interface when the data is sent every 10 second.

setInterval(sendData,10000);

This is what’s getting called:

function sendData(){
     var xhr = new XMLHttpRequest();
     var localData = datatodatabase;
     xhr.open("POST", "handler.php", false);
     xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xhr.send("pack="+datatodatabase);
}

Is it possible to add this inside a Web Worker to make the synchronized requests stop delaying what everything else is going on?

(As I said: I have to use synchronized because of onbeforeunload)

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

    Why don’t you make it asynchronous every 10 seconds, but onbeforeunload make it synchronous? Like this:

    setInterval(function () {
        sendData(true);
    }, 10000);
    
    window.onbeforeunload = function () {
        sendData(false);
    }
    
    function sendData(async) {
        // Make the ajax call the specific way based on whether *async* is *true* or *false*
    
        // Probably eventually:
        xhr.open("POST", "handler.php", async);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a site collection inside a web application with user A as
Currently I have a web application where a user can use dropdown lists to
I have a simple web application which lets the user upload local user data
I have put a form on a web page where the user can send
I am working on an asp.net/C# web application, In the main page: I have
Here's the situation: I have a web application which response to a request for
I am developing a web application which takes user inputs, does engineering calculations and
I have a simple page in a PHP/MySQL web application that lets admin users
I have a web application that begins with a login page. During the verification
I am developing a GWT web application. I have a login page with one

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.