The status of the xmlhttprequest remains unchanged even after the connection has been re-established

I need to continuously send an http request until I receive a positive response. When the wifi on my laptop is active, the program exits successfully. However, if the wifi is turned on while the program is still attempting, I do not get the desired response and the program keeps retrying until it eventually exits. Shouldn't the xmlhttp.status be 200 when the wifi is activated?

xmlhttp = new XMLHTTPRequest();
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader('User-Agent', 'XMLHTTP/1.0');

data = "Some text here";
xmlhttp.send(Base64.encode(data));

var timeout = 16;
var response = '';

for (var t = 0; t < timeout; t++) {

    if (xmlhttp.ReadyState == 4) {

        // If the XMLHTTPRequest returns status code 200 (OK) and the response text contains REPORT_SUCCESS, then the report was successful.
        if (xmlhttp.Status == 200 && xmlhttp.ResponseText.indexOf(REPORT_SUCCESS) != -1) {

            return true;
        } else {
            if (xmlhttp.Status == 200) {
                // if the XMLHTTPRequest returns status code 200 (ok) but the response text does not contain REPORT_SUCCESS
                break;
            } else {
                //try again 
            }
        }
    }

    WScript.Sleep(1000);
}

Answer №1

When the wifi is off, the xmlhttp request completed with an error response. It does not automatically retry the request when the wifi is turned back on - you will need to do this manually.

The ReadyState remains at 4 and the Status is not equal to 200 in a continuous loop.

Your code will function properly if the xmlhttp starts sending requests at the same time that the wifi is turned on.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Embedding external javascript within another javascript file

I have two pieces of code - code 1 and code 2. Code 1 is login.html which I am saving as login.js, and code 2 consists of some jQuery and JavaScript codes. My problem is how to insert the first code into the second code. Code 1: login.html (saved as logi ...

Best practices for updating the token in an Angular 2/5 application - tips on how, where, and when to refresh

Currently I am utilizing the following technologies: Django REST Framework Angular 5 RxJS + OAuth2 Within all components paths except LoginComponent, I have an AuthGuard to verify the token data stored in localstorage of the browser. If valid data is ...

How can I enlarge the arrow of the React Tooltip component?

I've extensively reviewed the official documentation, but I couldn't find a way to adjust the size of the arrow in the React tooltip. <span className="icon margin-10-right txtSize20 txtBlue icon_profile-menu icon-tool" data-tip={`&l ...

What steps can be taken to solve the JavaScript error provided below?

My objective is to create a new variable called theRightSide that points to the right side div. var theRightSide = document.getElementById("rightSide"); Once all the images are added to the leftSide div, I need to use cloneNode(true) to copy the left ...

Retrieving multiple images from a directory and storing the image filenames in a JSON array

Currently, I am attempting to locate and retrieve the images stored within a specific folder using the following code. This code successfully retrieves the image names along with the total count of images. Subsequently, my goal is to save this information ...

Using Sequelize to update all values in a JSON file through an Express router.put operation

I've been working on a feature in my Express router that updates data in a MySQL schema for 'members' of clubs. The members table has various columns like member_id, forename, surname, address, etc. I've successfully created an Express ...

It appears that the SignalR proxy is not defined

Why is $.connection.connectionhub showing as undefined? I am using webform. <script src="/scripts/jquery-1.6.4.min.js"></script> <!--Reference the SignalR library. --> <script src="/scripts/jquery.signalR-2.2.1.min.js">< ...

Why is it that a JSX element can take a method with parentheses or without as its child?

Why is it that when I attempt to pass a method without parentheses into a React component as a child of one of the JSX elements, an error appears in the console? However, simply adding parentheses resolves the issue. What's the deal? For example: ran ...

Is there a way to remove a dynamically rendered component from a list?

Whenever I click a button, the same component is dynamically rendered on top of the list. But now, I need to implement a feature where users can delete any component from the list by clicking a cancel button associated with each component. Here's my ...

Encountering Webpack issues following the transition to Next 13

Since updating Next to version 13, we've encountered issues with our application not building properly. It appears that webpack is having trouble with imports, exports, and potentially typescript. ../../libs/queries/src/lib/groq/searchFaq.ts Module pa ...

How about this: "Unveil the beauty of dynamically loaded

var request = new Request({ method: 'get', url: 'onlinestatusoutput.html.php', onComplete:function(response) { $('ajax-content').get('tween', {property: 'opacity', duration: 'long&apos ...

Updating style in Javascript can sometimes be a bit tricky

What's preventing this from working? localStorage.fontSize contains the correct value, but the initial document.body.style.fontSize = localStorage.fontSize + "pt"; doesn't update the style. <script type="text/javascript> if(!localStorage. ...

What is the process for updating the Vue template during runtime?

Currently, I am working on a CMS-based Vue page. Within this page, there is a root container that contains two child containers structured as follows: <div id="app"> <div class="above-the-fold">...</div> <di ...

What steps should I take to design and implement this basic search form?

Essentially, I have a three-page setup: - One page containing all possible search results such as: 'search result 1' 'search result 2' 'search result 3' - Another page with a search form and enter button. - And finally, a res ...

Error message indicating unauthorized access while trying to implement Backbone with Slim framework and Tuupola basic authentication

I've been working on connecting my Backbone app with my server API (using Slim) and have implemented Tuppola / Basic Auth Middleware to handle authentication. The setup is fairly simple, as I'm just trying to make it work. When I access the serv ...

Showing key-value pairs from an array of objects using Angular TypeScript

Within my angular application, I am fetching a dynamic list of objects from an API. A sample of the data structure is as follows: [ { "_id": "some id", "DATE": "2021/01/08", "COUNT&qu ...

SyntaxError: Unexpected symbol

I have an issue with the following code: let op = data.map(({usp-custom-90})=> usp-custom-90 ) When I run it, I encounter the following error: Uncaught SyntaxError: Unexpected token - I attempted to fix it by replacing the dash with –, but t ...

Is incorporating RequireJS into an AngularJS project a valuable decision?

Is it true that AngularJS has its own module loading mechanism built-in and using RequireJS is unnecessary or even inefficient? I am working on an Angular project where the index.html file is becoming quite large. Would incorporating RequireJS help reduc ...

Rendering a dynamic list of links to Partial Views in ASP.NET MVC 3 view

Within my MVC 3 application, I am planning to implement a view that will include a partial view. The main view will feature a dynamic list of links that, when clicked, should display detailed information in the partial view. I am considering using Ajax fo ...

The Node.js websocket server (utilizing the ws module) is not operating in a secure manner

I am facing an issue with my websocket server setup on a secure domain with SSL. It seems that the server is not using wss protocol, but instead sticking to ws. Below is the code snippet that shows how the WebSocket server is created: const httpsServer = ...