Is the XMLHttpRequest object closed once the response is received?

Attempting to establish a connection with the server using an XMLHttpRequest object to send data intermittently. The process of creating the object and establishing a connection is as follows:

var xhr = new XMLHttpRequest();
xhr.open("post", location, true);
xhr.send(); //Should the send call be used to open the connection?

Subsequently, a request is made at a later time:

xhr.send("Data to be sent");

However, upon examining the developer console, it appears that only the initial request was successfully processed and responded to. The second request does not appear to be sent. To troubleshoot the issue, the query of whether the connection is closed once a response is received arises; Furthermore, is there a method to keep the connection open continuously to maintain reconnection?

Answer №1

A server will close after sending a response if you haven't found a way to keep it alive. Consider exploring websockets for more advanced communication. If you prefer to stick with HTTP, just make a new HttpRequest for each request. Remember that websockets are a feature of HTML5 and may not be fully supported by all browsers.

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

Build a React application using ES6 syntax to make local API requests

I'm really struggling to solve this problem, it seems like it should be simple but I just can't figure it out. My ES6 app created with create-react-app is set up with all the templates and layouts, but when trying to fetch data from an API to in ...

How can I place an icon on a specific location in a Highcharts map?

I am currently utilizing Highcharts to showcase maps within my application. I am aiming to achieve two specific functionalities: 1) Upon clicking on any area, I want that area to be highlighted in red {completed} 2) Upon clicking on any area, I intend f ...

Encountering a npm error E404 when trying to install unicons package for React development

I recently started working on a weather app project using create-react-app and encountered an issue while trying to install unicons for the project. Despite attempting a few solutions, I was unable to resolve the problem. Here is the command I used for th ...

Unable to transmit the error information to a response

Currently, I am in the process of making a POST request with a form-data type body. Within the body, there is specific data that can be found here: https://i.sstatic.net/XvRgJ.png In order to parse the data field (which is stringified JSON) in the body ...

Every time I try to use AgGrid selectors, they consistently come back with null results, even though the

I currently have an ag grid in my application: <app-my-component> <ag-grid-angular [gridOptions]="gridOptions" (gridReady)="setGridReady()"> </ag-grid-angular> </app-my-component> When running Karma- ...

The jQuery remove function will only take effect on the second click following an AJAX request

I'm facing an issue with my jQuery code where two divs contain lists of links, triggering AJAX calls to append JSON data to a separate div. Upon clicking a link, the corresponding link div should hide. There's also a third div with the class "pan ...

jquery.event.drag - Execute code for each increment of X pixels dragged

Currently, I am utilizing jquery.event.drag.js for a project I am developing. My goal is to execute a script after every interval of X pixels dragged along the X axis. Below is a snippet of the code I have implemented. $('body').drag(function( e ...

Could you provide insight into the reason behind debounce being used for this specific binding?

function debounce(fn, delay) { var timer return function () { var context = this var args = arguments clearTimeout(timer) timer = setTimeout(function () { fn.apply(context, args) }, delay) ...

I am having trouble getting the graph to display using PHP and MySQL on Fusion Charts

I am looking to create a line graph based on data from my database. This is my first time working with Fusion Charts, so I followed the instructions in their documentation for dynamic charts. Here is the code from my PHP page: <?php include("Includes/F ...

Uploading files with AJAX in CodeIgniter using Dropzone and CSRF security measures

Utilizing the dropZone JS jQuery plugin in conjunction with CodeIgniter for uploading images has presented an issue. A reset button is available on the form to allow users to upload a new image, but after resetting the form and attempting to upload again, ...

Using PHP and JQuery to redirect a page by initiating an AJAX request

I have set up a forum on my website that functions using AJAX requests, meaning that the URL remains unchanged. When a button is clicked, an AJAX request is made to a PHP file and the client's response is updated. This system is working well for me, b ...

Troubleshooting: Why Laravel 5 VueJS Integration is Failing

I have recently set up a Laravel project and am attempting to integrate Vue.js into it. After running the following commands in my terminal: npm install npm run dev The commands executed without any errors. However, when I tried to import the default Vue ...

Always keep your phone in landscape orientation for optimal website viewing

Currently, I am facing an issue with my website where it functions perfectly on mobile devices in landscape orientation but elements get distorted when viewed in portrait mode. Is there a method to ensure that the website is always displayed in landscape ...

Tips for preventing the inner surface from appearing transparent in WebGL

I am working with the code snippet provided below. The issue I am currently facing is that one side of the partial sphere is non-transparent, while the other side remains transparent. How should I modify the code to make both sides non-transparent? Thank y ...

Using the power of ReactJS, efficiently make an axios request in the

After familiarizing myself with Reactjs, I came across an interesting concept called componentDidUpdate(). This method is invoked immediately after updating occurs, but it is not called for the initial render. In one of my components, there's a metho ...

Angular keeps throwing an error saying "Provider not found" when trying to inject a factory

Issue: Encountering an Unknown Provider Error in Angular App for: UnitProvider <- Unit Error Details: Error: [$injector:unpr] Unknown provider: UnitProvider <- Unit Codepen Link: View LIVE CODE Example I recently came across a fascinating vide ...

How to prompt the browser to download a file with a specific name using node.js and express

I've created a node/express website as part of my university project. It allows users to search for a specific law ID, which then displays a table with various files in different formats and languages related to that ID. I am using the "http-proxy" mo ...

Updating parent scope data from within a directive without relying on isolated scope bindings

What is the best method for passing data back to the parent scope in AngularJS without using isolated scopes? Imagine I have a directive called x, and I want to access its value named a. The desired syntax would be: <x a="some.obj.myA"></x> c ...

Using NodeJS to extract information from Opendata JSON files

I'm currently working on a project that involves fetching JSON data from an Open Dataset using NodeJS and passing it to angular. The challenge I'm facing is that I'm receiving a JSON file instead of a JSON object, which makes it difficult to ...

A guide on sending parameters from a form to a controller in Spring using JSON

In my current project, I am utilizing Spring and a web service to submit and make phone calls by passing phone numbers as JSON data. I am aiming to receive a URL in the following format: https://myservice.com/oapi/v1/call/click-to-call/phoneNumber The pho ...