The loading icon on Chrome continues to rotate while handling XMLHttpRequest requests

I'm currently developing a web app using AJAX with Comet/Long Polling to ensure real-time updates on the web page. I've noticed that in Chrome, the page is constantly loading (tab icon keeps spinning).

Initially, I thought this was a normal behavior for Google Chrome when working with Ajax, as even Google Wave exhibited the same behavior.

However, today I observed that Google Wave no longer shows the spinning loading icon. Does anyone know how they managed to fix this issue?

Below is the code snippet for my AJAX call:

var xmlHttpReq = false;
// For Mozilla/Safari
if (window.XMLHttpRequest) {
   xmlHttpReq = new XMLHttpRequest();
}
// For Internet Explorer
else if (window.ActiveXObject) {
   xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('GET', myURL, true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange = function() {
   if (xmlHttpReq.readyState == 4) {
      updatePage(xmlHttpReq.responseText);
   }
}
xmlHttpReq.send(null);

Answer №1

I shamelessly borrowed Oleg's test case and made some adjustments to mimic long-polling behavior.

load.html:

<!DOCTYPE html>
<head>
  <title>Example showcasing the issue with jQery.load</title>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
  jQuery(document).ready(function() {
    $('#main').load("test.php");
  });
  </script>
</head>
<body>
  <div id='main'></div>
</body>
</html>

test.php:

<?php
  sleep(5);
?>
<b>OK!</b>

The outcome is intriguing: Firefox and Opera do not display a loading indicator during XMLHTTPRequests, while Chrome keeps it spinning. I have a suspicion that Google Wave may no longer utilize long polling (opting for periodic polls instead) to conserve resources, but I cannot confirm this without an account.

EDIT: I've discovered a solution: by introducing a slight delay in loading test.php, even if minimal, the loading indicator halts once load.html has been fully loaded:

jQuery(document).ready(function() {
  setTimeout(function () {
    $('#main').load("test.php");
  }, 0);
});

As discussed in a comment on another post, when the browser regains control to finalize page rendering, the spinning indicator ceases. An added benefit is that the request cannot be interrupted by pressing Esc.

Answer №2

Apologies for the broad response, but if you're looking to create a program that is more compatible across different browsers, consider using jQuery or another preferred library instead of lower-level tools like XMLHttpRequest and ActiveXObject("Microsoft.XMLHTTP").

UPDATE: I set up two simple HTML files: test.htm and load.htm in the same web directory (you can view them at this URL ). I didn't observe the issue you mentioned in your question. Compare these files with your examples to troubleshoot your problem.

load.htm:

<!DOCTYPE html PUBLIC
          "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head">
  <title>Demonstration of the jQery.load problem</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript">
  jQuery(document).ready(function() {
    $('#main').load("test.htm");
  });
  </script>
</head>

<body>
  <div id='main'></div>
</body>
</html>

test.htm:

<b>OK!</b>

Answer №3

I encountered a challenge with inserting snippets into Ace Editor using the Snippet Manager, similar to your issue with jQuery or Ajax. During page load, inserting code into the editor caused the page to appear stuck, indicated by a perpetually spinning tab icon. Utilizing .setTimeout() yielded inconsistent results - functioning when the page loaded swiftly but failing when loading was slower. This inconsistency may have resulted from not enclosing the code within $(document).ready() and instead placing it at the end of the document body.

To address the perpetual spinning tab icon without relying on jQuery, I implemented the following solution:

var checkPageLoad = setInterval(function() {
    if( document.readyState === 'complete' ) {

        clearInterval(checkPageLoad);
        // perform desired action

    }    
}, 5);

In my scenario, the "// perform desired action" segment entailed:

ace.config.loadModule('ace/ext/language_tools', function () {
    myEditorInstance.insertSnippet( 'some string' );
});

Answer №4

use the following code snippet

function createHTTPRequest() {
 var httpRequest = false;
 if (window.XMLHttpRequest) {
  httpRequest = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
  try {
   httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
   try {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e) {
    httpRequest = false;
   };
  };
 };
 return httpRequest;
};

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

Issue with Kaltura thumbnail video not rendering within a script tag in React, resulting in blank space instead

I have encountered an issue with a Kaltura Thumbnail embed in React. When I use the script tag in a basic HTML page, everything works fine. However, when I try to use the same script tag in React, it only shows an empty space instead of the video. On ins ...

Implementing double dependent dropdown functionality using Ajax in CodeIgniter

My issue involves two dropdowns where the result is supposed to appear in a text input. However, when the second dropdown has multiple selections, the result always reflects the last selection made. For example, if the first dropdown has options A and B, t ...

What could be causing the <img src= ' '/> tag to malfunction in Express?

While learning about HTML, I noticed that simply using img src="...." worked fine. However, when working with Express, the same code did not work! The documentation mentioned that I needed to place the images in a folder named public, require(&ap ...

Passing data between parent and child components within an Angular application using mat tab navigation

I am currently working on a project, which can be found at this link. Current Progress: I have implemented a mat tab group with tabs inside the app-component. When a tab is clicked, a specific component is loaded. Initially, most of the data is loaded in ...

Tips for incorporating various color schemes into all sides of a shape generated through the extrude geometry feature in three.js

I have recently designed a wall-like structure using extrude geometry and now I want to assign different colors to each side based on the settings below: var extrusionSettings = { curveSegments:5, steps: 10, amount: 200, be ...

Apexcharts tends to be unreliable upon dashboard loading, frequently appearing and disappearing unpredictably

Having trouble with displaying apexcharts on my dashboard. There are 5 charts on the dashboard and their behavior is acting strange. The charts only show up after reloading the page 3 to 4 times or when inspect element is clicked. Otherwise, only 2 or 3 ch ...

What causes this loop to operate in one location but not in another?

import { log, logTitle } from "logger"; var persons = [ {name: "Alex", age:22}, {name: "Maria", age:30} ] var number = 0; for (var i = 0; i <= persons.length; i++) { log(persons[i].name); log(persons[i].age); l ...

How will SEO be impacted if content is concealed using jQuery or JavaScript?

I'm currently developing a web application template for support documentation. While most of the content will be initially hidden to streamline the design, I am considering incorporating detailed descriptions to enhance SEO. These descriptions would b ...

Vue.js: Error 404 - POST request endpoint not found

My goal is to access my Quasar application from other devices connected to the Local Area Network. I have successfully run the app on these devices, but I encountered an error POST http://10.0.0.20:8080/MyComposer/?submitId=3 404 (Not Found) when trying to ...

How can jQuery identify words of a certain length within a string?

Is there a more efficient way in jQuery to identify if a string contains words with a specified length or less? Rather than looping through each word individually as I planned, I'm wondering if there is a built-in function or easier approach available ...

The form is refusing to submit even after using the "return false

Even after adding validation to the form, it still submits when the script returns false. The Form Submission <form action=payment.php method=POST name=UserForm id=UserForm onsubmit="return check(this); return false;"> Javascript Code function ch ...

Tips for integrating Twitter sharing functionality in React JS

I am looking for a way to enable users to easily share images from my website on Twitter. Although I tried using the react-share module, it does not provide an option to directly share images. This is the snippet of code I currently have: import { Sh ...

Importing multiple exports dynamically in Next.js

My current setup involves using a third-party package that I load dynamically in Next.js: const am5 = dynamic(() => import("@amcharts/amcharts5"), {ssr: false}) The imported amcharts5 consists of various exports and imports, such as: export { ...

Guide on transmitting the capabilities to the Testdroid server

Need help with sending desiredCapabilities to appium server While trying to run the appium server, I keep getting an error message saying "You must include a platformName capability". Could someone please explain how to correctly send the desiredCapabili ...

Encountering an issue when trying to execute a JavaScript script using capybara/selenium in a Ruby environment

As a beginner in the world of Automation, I am utilizing Selenium, Ruby, and Capybara to execute this JavaScript script. However, I encountered an error message that says: "Selenium::WebDriver::Error::UnknownError: unknown error: Runtime.evaluate threw exc ...

Mobile version experiencing issue with Navbar not collapsing

The dropdown navigation bar on the mobile version of my website is not functioning properly. Despite several attempts, I have been unable to figure out a way to make it work effectively. <!DOCTYPE html> <html lang="en"> <head> & ...

Exploring the process of generating, monitoring, and initiating personalized events in ReactJS

To establish a global custom event for listening and triggering purposes, here is how it can be achieved using jQuery: $(document).on('myCustomEvent', function(){ console.log("myCustomEvent triggered"); }) $(document).trigger('myCustom ...

How can one elegantly deal with invalid arguments in JavaScript?

Imagine a scenario where I have a function that specifically accepts non-negative numbers, but is given a negative argument. If this were in Python, I would raise a ValueError. In Java, an IllegalArgumentException would be thrown. Is there a built-in exce ...

Is there a way to collapse an element by clicking either the content inside the div or the button within the div?

Is there a way to make a button within a newly activated div close it? The existing code seems to have issues with this functionality, and adding new rules or functions has not solved the problem. Any assistance with fixing this issue using vanilla JavaScr ...

Ways to identify when a browser has disabled JavaScript and present a notification

Is there a way to detect if JavaScript is disabled in the browser and show an error div instead of the body? ...