The functionality of jQuery and CSS to display the busy cursor is not always reliable

For a project I'm working on, I am utilizing PrimeFaces ajax to retrieve elements on my web pages. To enhance user experience, I wanted to change the mouse cursor to a "busy cursor" during certain PrimeFaces ajax events that may take some time to complete.

To achieve this, I included the following code in my css file:

html.wait, html.wait * {
   cursor: wait !important;
}

To toggle the class, I inserted the following code snippets in my xhtml files where the PrimeFaces components using ajax are located:

onstart="$('html').addClass('wait');"
oncomplete="$('html').removeClass('wait');"

These xhtml files reference a template xhtml file that links to the css file.

The initial test run after implementing these changes was successful, but later, upon logging out and back into my computer, the functionality stopped working. Despite no other alterations to the project, the issue remained inconsistent. After numerous login/logout attempts, it only worked properly for two sessions. When it does work, it remains functional throughout the session with all ajax events. Interestingly, if I copy the project and import it into another Eclipse environment, it works as expected. However, the inconsistency persists after subsequent logins.

Although unlikely related, my project is built using PrimeFaces 10.0.0 and JSF 2.2.9.

The sporadic behavior without any code modifications baffles me. Any suggestions or insights on what might be causing this would be greatly appreciated. If additional information would be helpful, please do let me know.

UPDATE

I attempted setting the global attribute to true on the PrimeFaces components while incorporating the following code:

<p:ajaxStatus onstart="$('html').addClass('wait');" oncomplete="$('html').removeClass('wait');"/>

This method also did not yield the desired outcome. As similar approaches work correctly, such as:

<p:ajaxStatus>
    <f:facet name="start">
        <h:outputText value="Sending" />
    </f:facet>
    <f:facet name="complete">
        <h:outputText value="Done" />
    </f:facet>
</p:ajaxStatus>

This suggests a potential issue with jQuery/css rather than PrimeFaces.

Update

A recent observation in the browser revealed that the updated css file with the specified line was not being utilized.

Answer №1

Execute this script and watch the changes with your mouse cursor before the webpage finishes loading

  $.ajax({
   beforeSend: function(){
      $('html').addClass('waiting')
   },
   complete: function(){
       $('html').removeClass('waiting')
       $('p').html('Ajax request completed successfully');
   }  
 });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<style>
.waiting{
   cursor: wait !important;
}
body {
  background-color: lightblue;
}

h1 {
  color: white;
  text-align: center;
}

p {
  font-family: verdana;
  font-size: 20px;
}
</style>
</head>
<body>

<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>

</body>
</html>

Answer №2

It seems like I'm getting the hang of it! Moving the mouse triggers a change in cursor, but it's not always consistent.

function do_ajax() {

  try {

    $.ajax({
      beforeSend: function() {
        $('body').addClass('wait')
      },
      complete: function() {
        $('body').removeClass('wait')
      }
    });
  } catch (e) {}
}

do_ajax();
body.wait,
body.wait {
  cursor: wait !important;
}

body {
  background-color: lightblue;
  text-align: center;
}

h1 {
  color: white;
}

p {
  font-family: verdana;
  font-size: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<body>

  <h1>You have to move your mouse</h1>
  <p>In order to see cursor change</p>
  <button onclick="do_ajax()">do_ajax()</button>
</body>

Answer №3

It came to light that the server I had been utilizing had a cache stored in the browser, causing the css not to be updated. To address this issue, I opted to clear the browsing history. For additional solutions, refer to this post.

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

Seamless shifting between different content images

.tidings { width: 30%; float: left; margin: 0 3%; } .tidingsimg:before{ content: url("https://s4.postimg.org/466igrsgt/Tidingsrune.png"); position: relative; transition: opacity 1s ease; -webkit-transition: opacity ...

Is it possible to create a blurred effect on an image while preserving the clarity of text within

I have been attempting to create an effect where the image blurs and then reveals text. However, I have encountered issues where the image either blurs completely or behaves strangely. My code is behaving oddly, almost like it's giving a signal. (I&a ...

unable to access information from the JavaScript file

I am experiencing an issue with the code that fetches data from a database using AJAX. I have double-checked the table names and syntax, but I still cannot retrieve the data. Filename: ajax_check_uname.php <?php $dbhandle = mysql_connect('l ...

Symfony Form Validation through Ajax Request

Seeking a way to store form data with Symfony using an Ajax call to prevent browser refreshing. Additionally, I require the ability to retrieve and display field errors in response to the Ajax call without refreshing the page. I have a Symfony form setup ...

Constantly vibrating a container

I'm currently using this code snippet, but I would like to introduce a pause of around 500 milliseconds or half a second before the loop continues. Is there a way for me to modify the existing implementation to achieve this effect? jQuery.fn.shake = ...

What could be causing my jQuery getJSON function to not execute the callback function as expected?

I'm facing an issue with my JavaScript code: $(document).ready(function(){ $("#EstadoId").change(function(){ listaCidade($(this).val()); }); }); function listaCidade(uf) { $.getJSON("@Url.Action("ListaCida ...

Form with upload and submission options

I need your assistance with PHP. I want to create a form that includes both an upload button and a submit button. Is it possible to have two button elements within one form, or do I need to separate them into two separate forms - one for the upload butto ...

Tips for creating a mandatory textarea input field

It's pretty straightforward - I have a textarea that is set to required, but it only alerts the user if you actually click inside the text area. If you try to submit without clicking inside, it won't prompt the alert. Take a look at this Fiddle ...

What is the best way to arrange these divs one on top of another?

I have combed through numerous resources but still haven't found a solution to my problem. I am struggling with figuring out how to stack the "top_section" div on top of the "middle_section" div. Currently, "middle_section" is appearing above "top_sec ...

Loading options dynamically in a dropdown list using KnockoutJS

I am new to KnockoutJS and I have successfully worked with static data in dropdown lists. Now, I need to dynamically populate the dropdown list from a controller. 1. I want to retrieve a dynamic list from my controller and populate it in a dropdown list. ...

Dynamic banner image

I currently have a jumbotron image in the background, but it isn't as responsive and I'm struggling to get the whole image to display properly. Here is what it looks like currently: https://i.sstatic.net/IpuDi.png Here is the full image for ref ...

Creating a unique design for a CSS menu with distinct section dividers and stylish onHover effects

Hey there! I'm currently working on a new menu design using UL and LIs elements. I would really appreciate some advice on how to add lines after each LI and properly indent them with the specific bullet image I have chosen. If you're interested ...

Create a stunning wave CSS effect using the :after and :before pseudo-elements

Hey there! I'm currently experimenting with creating a wave effect using CSS, specifically utilizing 'before' and 'after'. However, I've encountered an issue where I can't seem to position my waves correctly at the top a ...

jquery ajax file uploading issue: success function not triggering

Having issues with the file ajaxfileupload.js while using jquery for uploading images to a Joomla site. The upload is successful, but the "success" function isn't being called as needed to show confirmation of completion. Using "complete" works but ca ...

When trying to load a php page2 into page1 via ajax, the Javascript code fails to execute

Currently, I am in the process of learning PHP and JavaScript. I have encountered a particular issue with a webpage setup. Let's say I have a page called page1 which consists of two input fields and a button labeled 'Go'. Upon clicking the & ...

Display scroll bars over the position:absolute header

My container has content that exceeds its size in both directions. To see the issue, try scrolling horizontally and vertically on the table available here: The vertical scrollbar is visible as desired, except that it gets hidden behind the table header un ...

"Finding specific data on a list with ease - A guide to scrolling using a searchbox

One interesting feature of my project is the search box that allows users to quickly find specific data in a populated div list sourced from the database. When a user types something into the search box, the corresponding data will be scrolled to on the li ...

The error message "Unable to access property 'x' of undefined" is appearing in the photoswipe js

There is an error in the library when using photoswipe.min.js: "Uncaught TypeError: Cannot read property 'x' of undefined" The code for myPhotoswipe is identical to the one on the official site: var initPhotoSwipeFromDOM = function(gallerySelec ...

What is the best way to link data from SQL Server to an HTML webpage?

Seeking assistance on how to display data from a SQL Server database in an HTML page using JavaScript, AJAX, and jQuery without the need for C#, PHP, VB.NET etc. Can someone please provide some reference links or share example code? ...

I'm confused as to why my alert is not triggering after the ajax request successfully returns

I am having an issue with displaying an alert to my user before the page is submitted when making an AJAX call to a controller. Despite successfully sending parameters, the alert is not showing up. Can someone please take a look at the code below and off ...