Javascript/AJAX request failing to function correctly in Internet Explorer and Chrome

I am currently working on a PHP/JS script that will help me manage the status of all the windows terminal servers. The WMI access is quite slow, so I decided to use AJAX to display the progress of each server as it loops through them. The script works perfectly fine in Firefox. However, in Chrome, it does not show the status while looping; only after the loop is completed. And in IE11, the code simply doesn't work at all. Even though IE calls both functions and enters the if statement to create the request object. Can anybody assist me in getting IE to work properly and Chrome to display the status during the loop? Thank you for any help you can provide.

Here's my current code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="tsmanager.css">
<script type="text/javascript">
function refreshall()
{
var table = document.getElementById("terminalservers");
for (var i = 0, row; row = table.rows[i]; i++)
{
var sComputer = row.id;
if (sComputer != "")
{
setTimeout(refresh(sComputer), 2000);
setTimeout(document.getElementById("turn").innerHTML = sComputer, 2000);
}

}

}

function refresh(sComputer)
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else 
{
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
req.onreadystatechange = function()
{
if (req.readyState == 4 && req.status == 200)
{
document.getElementById(sComputer).innerHTML = req.responseText;
}
}
req.open("GET", "serverrequest.php?name="+sComputer, false);
req.send();
}

</script>
</head>
<body>
<table id="terminalservers">

  /* some table content with row id=servername */


</table>
<button onclick="refreshall()">alle</button>
<br><span id="turn">leer</span>
</body>
</html>

Answer №1

My recommendation is to consider utilizing jQuery for its reliable cross-browser AJAX support, leading to clearer and more concise code across the board.

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

Adjust the size of the external JavaScript code

Is it possible to adjust the size of the div element created by the external javascript code below? I've tried wrapping it in a div and setting the width, but the resizing doesn't seem to work. <div width = "100"><script type="text/jav ...

JavaScript regular expression to switch menu

Could someone clarify the meaning of this code snippet: /expanded/.test(classes) I understand that the '/' characters indicate a regular expression and 'expanded' is a class name. However, I am unsure about what .test(classes) does ...

Empty value for $_POST variable following xmlhttp request

When my code makes an xmlhttp request to a php file with an ID for record deletion from the database, I encounter an issue. The error message 'comicID' is undefined shows up when attempting to delete. This signifies that the variable containing t ...

Issue with ng-show directive in AngularJS

Currently, I am developing a web app using AngularJS 1.6.6. In my template, I have implemented ng-show in order to recycle it: <div > <br/> <div class="form"> <form data-ng-submit="objectHandlerVM.functions.objectHandl ...

Utilizing ng-pattern in Angular to detect leading zeroes in alphanumeric input fields

Are you wondering how to identify a leading zero in an alphanumeric field using ng-pattern in angular? <body ng-app> <h1>Regex test</h1> <form name="myForm"> <input name="myNumberField" ng-model="myNumber" ng-pa ...

Tips for retaining filled data after an incomplete form submission

<html> <head><script type="text/javascript"> function pa(){ var fname = document.getElementById('fname').value; var lname = document.getElementById('lname').value; var email = document. ...

Creating dynamic email templates in Node.js

I am working on a project using the MEAN stack and I need to implement email functionality. I have created separate email templates, but I want to include a common header and footer in all of them. Route.js router .route('/api/user/register&a ...

The truncation of the Gantt Highcharts layout

After analyzing the incoming data, I successfully generated a gantt chart. However, I am facing an issue where the last row is not displaying correctly and is getting cut off. Despite spending a significant amount of time examining it, I have been unable t ...

Can someone guide me on how to write this specific pug function using handlebars syntax?

Can anyone help me convert the pug code below into handlebars code? ul for product in products li #{product.product} li #{product.price} I have found some existing code but I need to populate two points per iteration. Any ideas ...

Getting just the month and year from the material-ui date picker value

I have updated a date picker to only allow users to select the month and year. However, I am now facing the challenge of extracting only the desired data (month and year) from the string it returns such as: "Thu Feb 18 2010 21:11:54 GMT+0800 (China S ...

Displaying a meager 0.5% on the BootStrap progress indicator

Utilizing the bootstrap progress bar to display the percentage of a person's miles covered out of a total of 23,872 miles. Take user A as an example, they have covered only 5 miles: 5/23872 = 0.00020945 * 100 = 0.02094504 miles. Currently, anything ...

Using the Angular routeProvider to pass data between scopes

Implementing routeProvider for deep linking in my app has been challenging. I am facing an issue where I need to accommodate multiple levels. For example, if I have a products page, the link would look like this: http://example.com/#/products The $scope. ...

Navigating Google Oauth - Optimal User Sign in Locations on Frontend and Backend Platforms

What are the distinctions between utilizing Google OAuth versus implementing user sign-ins at the frontend of an application, as opposed to handling them on the backend? For instance, managing user authentication in React to obtain the ID and auth object ...

Updating NPM yields no changes

Having trouble updating dependencies in a subfolder of my MERN stack app. Specifically, I am trying to update the dependencies in the client folder where the React code is located. However, when I attempt to update the dependencies in the client folder, it ...

What are the typical situations in which Node.js is commonly used?

Do you believe that a majority of node.js users primarily utilize npm? What do you think are the most prevalent use cases for node.js apart from npm? ...

Issue with JSON size leading to malfunction of Facebook wall posting feature in Internet Explorer versions 8 and 9

Recently, I've been utilizing the Facebook Javascript SDK for posting content from a CMS to a Facebook fan page. The process involves pulling current page content using jQuery and passing it into an FB.api function. Everything runs smoothly in Firefox ...

An elementary JavaScript class and object utilizing jQuery's "$(this)" for XML parsing

In the process of developing an XML parser for site definition files to control a website, I find myself encountering similar parsing procedures for many elements where retaining every value may not be necessary. Here is the XML file being parsed Check o ...

Transforming a Unix timestamp into a standard date format within a JSON object

I am currently working with Laravel 5.0 and receiving data from a controller in the form of JSON. The value I am seeing looks like this: {"timestamp_date":"1434360957"}, My goal is to convert this Unix timestamp value into a more conventional date format ...

Setting the class attribute dynamically using code behind

Below is a snippet of code I am working with: div1.Attributes.Add("class", "displayNone"); It functions properly during page load but fails to do so during an OnClick event. The issue arises from the fact that my HTML element <div id="div1"></d ...

React component failing to update when props change

After loading correctly, my react component fails to re-render when props change. Despite the fact that render() is being called and the list array contains the correct data according to console.log(list), the page does not refresh. Adding a setState in co ...