Chrome's spinner fails to appear when performing a synchronous ajax request in IE9

While implementing an ajax request, I want my users to see a spinner for visual feedback. Surprisingly, the spinner works flawlessly on Firefox 13, but fails to function on Chrome and IE9 even though the ajax request takes approximately 1.2 seconds to complete.

$('#fileManager').on('click', '.navSpan', function() {

    /* Display spinner */
    $('.fileManager-spinner').show();

    /* Synchronous ajax fetch and manipulation code here */

    /* Hide spinner upon completion */
    $('.fileManager-spinner').hide();
}

If I remove the

$('.fileManager-spinner').hide();
line, the spinner becomes visible in Chrome and IE as well, spinning as expected. However, with that line intact, it remains invisible.

Furthermore, when debugging the script and pausing execution between .show() and .hide(), the spinner continues to display on the screen. Yet under normal circumstances, it remains hidden.

Shown below is the HTML markup for the spinner:

<div class="fileManager-spinner" style="display: none;"></div>

And here is the CSS styling for the spinner:

.fileManager-spinner
{
    position:relative;
    top:50%;
    left:50%;
    margin-left:-50px; /* half width of the spinner gif */
    margin-top:-50px; /* half height of the spinner gif */
    text-align:center;
    z-index:1234;
    overflow:auto;
    width:100px; /* width of the spinner gif */
    height:102px; /*hight of the spinner gif +2px to fix IE8 issue */  
    background-image:url(../../Images/fileManager/loader/loaderBig.gif);
    background-repeat:no-repeat;
}

What could be causing this issue? Any insights would be appreciated. Thank you.

Answer №1

It appears that you are using synchronous ajax queries based on the information provided here. When using synchronous queries, Chrome's engine does not exit the javascript thread and does not update the screen.

To address this issue, consider switching to asynchronous ajax requests and removing the spinner in the callback functions.

Keep in mind that synchronous ajax queries will no longer be supported in future versions of jquery (1.8).

You can achieve this by:

// show spinner
$.ajax({
  url: "http://fiddle.jshell.net/favicon.png",
  // additional parameters
}).done(function ( data ) {
  // remove spinner
});

For more information, refer to jquery ajax done, always and fail functions.

Answer №2

When working with Ajax, it is important that the process remains non-blocking. In order to achieve this, you should ensure that your hide operation occurs within a function that is triggered after the completion of your Ajax request.

For instance...

$.ajax(...).done(function(){ $(".fileManager-spanner").hide(); });

By following this approach, your code should function as intended.

Answer №3

Take advantage of the predefined success parameter in your $.ajax function to trigger a specific task upon successful completion of the call.

If there is no particular justification for utilizing synchronous requests, I suggest transitioning to asynchronous requests for improved performance and efficiency.

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

JavaScript's connection to the CSS property visibility seems to be causing some issues

The Javascript code seems to be ignoring the CSS display property, even though it's set in the style sheet. I added a debugger statement and noticed that the display value was empty. I've been staring at this for some time now, so I must be overl ...

Customizing button appearances in the control div on Google Maps - A guide

Is there a way to manipulate elements and adjust styles by clicking buttons on the map control div? I want to achieve the same effect on the map as with the buttons in the table. Code: jsFiddle Update: Thanks to your assistance, I was able to achieve th ...

Toggle the visibility of dropdown list items in different ways: Add or Remove, or Show or

Currently, I am working on a project that involves 3 drop down lists for security questions. I have implemented javascript functionality that triggers an alert when a selection is made in any of the drop down boxes. My challenge now is figuring out how t ...

Unable to select jQuery dialog based on class name for elements loaded via Ajax

Update: issue resolved: By using event delegation, all 'problematic' elements that were dynamically created after the page loaded are now properly bound to the jQuery event. Original inquiry: I encountered this particular piece of code in my P ...

Having trouble populating the container with page content using AJAX, PHP, and JS?

Whenever I attempt to use the buttons to change the content, I keep receiving a 'There is no such page!' message. Below is the index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ...

Press on the menu <li> item to create additional submenus

A group of friends is facing a challenge. They want to create a dropdown sub-menu that appears directly below the selected item when clicking on a link from a menu. So far, they have been able to use ajax to send requests and generate a sub-menu. However, ...

Working with arrays containing numerical keys in JSON using jQuery

If I have a PHP file that generates JSON data with numerical keys like this: <?php $array[1] = "abcd"; $array[2] = "efgh"; $array[3] = "1234"; $array[4] = "5678"; echo json_encode($array); ?> How can I access the value associated with key 4? The i ...

When viewing HTML emails in dark mode on iOS Gmail, the CSS appears to be inverted

While sending an HTML email from a nodejs app, I encountered an issue with Gmail on iOS where elements with background-color or color properties were getting reversed. This was most noticeable on black and white elements. Despite consulting various guides ...

Using jQuery, how can I add value to every input when the option is changed?

I need help changing the values of all input:text elements based on selections from a select menu. Specifically, I want to change only the matched td.class values from the data-pset attribute inside the <select>. As a beginner in jQuery, I can only ...

jQuery Suckerfish with disabled animations

Currently, I am incorporating jQuery and the Suckfish plugin for my menu. However, I have a specific requirement - I do not want any animation to occur when the submenu is displayed. Although I have set the speed to 0, there still seems to be a slight del ...

When navigating to an external dialog, the rounded corners are no longer visible after changing the page

When using JQuery Mobile 1.3.1 to load an external view into the DOM using $.mobile.changePage, I ensure that the correct options are used to load the view as a dialog. However, I am facing an issue where the rounded corners on the dialog seem to disappear ...

Is it possible to Maintain a Constant Pixel Font Size while Allowing for Responsive Text Size?

When viewing a site like the mobile version of , I noticed that the text size adjusts responsively, but the active font-size remains constant at 34px. To see how this works on different screen sizes, check out this comparison. Even when changing the wind ...

Error message encountered: "Forbidden - CSRF cookie is not set while attempting a POST request with Django

In my Django 3 application, I have implemented jQuery Ajax posts on bootstrap modals. There are several buttons that do not belong to any form but trigger a post request to specific URLs. All Django methods follow the guidelines mentioned here: https://do ...

Having trouble interacting with element - Selenium WebDriver is not allowing the click

I'm attempting to select the Checkout Button. This is what it looks like : https://i.stack.imgur.com/TiMEO.png And here's the HTML snippet for it : <div id="buy-button-next"> <span data-reactroot=""> <div data-cid="buy- ...

What could be causing the issue of node-sass generated CSS files not loading on the initial GET request?

I've set up a node express app and incorporated sass support for the CSS. However, when I attempt to access http://myhost.com:port/css/whatever.css, the whatever.css file is generated in the express_app_root/public/css directory as expected. The *.scs ...

Webpack has made Rails .js.erb templates obsolete

Recently, I migrated my Rails application to use WebPack for handling assets, and it has been operating smoothly. However, I encountered an issue with JS templates located in my views directory (*.js.erb) that require jQuery. Since jQuery is included in my ...

Tips for displaying a div briefly before loading the second page

Incorporating a div named ADD, I aim to successfully load a second page within the current one using ajaxload. The challenge lies in displaying a div for 4 seconds before loading the second page. How can this be achieved? Following the wait period, the sec ...

Creating a disabled HTML button that reacts to the :active CSS pseudo class

CSS: button:active { /* active css */ } button:disabled { opacity: 0.5; } HTML: <button disabled="disabled">Ok</button> After clicking the button, the browser applies the button:active state to give the appearance of a click, despite the ...

What causes the odd gaps at the bottom of boxes in a Pure CSS Masonry layout?

Issue with implementing Pure CSS Masonry layout. Using position: relative for the boxes and position: absolute for the content inside each box is causing gaps below each box. Struggling to find a solution, view the code on this codepen: http://codepen.io/k ...

Phrases are truncated in the initial line of each ion-item within the ion-list

In Ionic 3, I am facing an issue with my ion-list where the first line inside each ion-item is getting cut off. Specifically, the capital 'A' letter is not entirely visible. Can anyone provide assistance with this? Thank you. Below is my code sn ...