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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:34:14+00:00 2026-05-26T17:34:14+00:00

I have a function in a .js file that takes information stored in localStorage

  • 0

I have a function in a .js file that takes information stored in localStorage and syncs them back to the server using synchronous ajax calls. (Order of integration is vital, hence synchronous is necessary)

function syncUp() {
    var xml = new XMLHttpRequest();
    xml.open("GET", "Default.aspx", true);  Also tried setting this to false
    xml.onreadystatechange = function() {
       if (xml.readyState == 4) {
         if (xml.status == 200) {
             var items = localStorage.getItem("SyncOrder");
             var sync = items.split(",");

             for (var i = 0; i < sync.length -1; i++) {
                 Perform repeated synchronous calls to webservice via AJAX to integrate each item to the server
              }
           }
        }
     }
  xml.send(null);
  }

syncUp() is being called from more than one place. When called directly from the onclick event of a button where syncUp() is the only function called and the only code running, it works great. However, if from a page where I am first adding an item to the localStorage object and then calling syncUp() as follows

function saveEdit(item) {
      var currData = localStorage.getItem("SyncOrder");
      localStorage["SyncOrder"] = currData + "," + item;
      syncUp();
}

, the xmlHTTPRequest status returns 0 and the sync doesn’t perform. What could possibly be preventing the xmlHTTPRequest from getting a response of 200 as the only code running before syncUp() is a couple lines of javascript, which should be done executing before the site even gets into syncUp()?

  • 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-26T17:34:14+00:00Added an answer on May 26, 2026 at 5:34 pm

    There are two causes of status code of zero.

    1. Making calls from the file protocol.
    2. The page is refreshing/navigating away as the request is being made.

    In your case I would assume it is #2. If you are using a button or a link to make the Ajax call, make sure to cancel the click action with either preventDefault or return false.

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

Sidebar

Related Questions

I have a function that takes 2 parameters : 1 = XML file, 2
I have some jQuery code. I have called an Ajax function file, file.php, that
Ok, so I have a function that takes the path to an image file
I'm getting an weird error using queues/multiprocessing. I basically have a function that takes
I have a php function I wrote that will take a text file and
In my Java code I have function that gets file from the client in
I have a function that automatically exports a table into a CSV file, then
I have one method that opens a file and passes off to another function
I have a 2884765579 bytes file. This is double checked with this function, that
Right now I have a function which takes my uploaded file, checks the extension,

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.