How can I display a warm and welcoming message when a task is finished?

I need help with my CodeIgniter application that is running some heavy tasks in the back end. I want to display a status message or box while the app is executing AJAX commands, and then clear it once the task is complete. Can anyone suggest what terms I should search for to find a solution for this?

Thank you.

Edit: Here is the current jQuery/AJAX code snippet I am using...

  $('#availVLANS').click(function()  {
  $(this).attr("disabled","disabled");
  $.ajax({
    url:"<?php echo site_url('controller/methodABC/');?>",
    type:'POST',
    dataType:'json',
    success: function(returnDataFromController) {
    var htmlstring;
    var submitFormHTML;
    htmlstring = "<br><br><B>To reassign the port to a new vlan, click on a VlanId below and then click on the OK button</B><br><table class='table table-bordered table-striped'>";
    htmlstring = htmlstring + "<th>VlanId</th><th>Name</th>";
    for(i = 0; i < returnDataFromController.length; i++) {
        //alert(returnDataFromController[i].VlanId);
        htmlstring = htmlstring +  "<tr><td><a href=>"+returnDataFromController[i].VlanId+"</a></td><td>"+ returnDataFromController[i].Name+"</td></tr>";   

    }
    submitFormHTML = "<form method='post' accept-charset='utf-8' action='" + BASEPATH + "index.php/switches/changeportvlan/"+ $('#ip').val() +"/" + $('#hardwaremodel').val() +"/" + $('#port').val() + "'><input type='text' name='newVlanID' id='newVlanID' style='width:5em;height:1.5em'/>&nbsp;&nbsp;<button type='submit' class='btn' name='saveVlan' id='saveVlan' style='width:10em;height:2em'>Reassign Vlan</button></form>";
    //alert(submitFormHTML);
    $('#clientajaxcontainer').html(htmlstring);
    $('#newvlanform').html(submitFormHTML);                     

  }
});
$(this).removeAttr("disabled");
  });

Answer №1

To implement a progress indicator using an animated GIF image, create an absolutely positioned DIV on top of the page. Ensure that you include an invisible overlay DIV to prevent clicks on underlying interface elements. Here's an example structure:

╔════════════════════╗
║  #progress-overlay ║
║ ╔════════════════╗ ║
║ ║ #progress-indicator
║ ╚════════════════╝ ║
╚════════════════════╝

The #progress-overlay serves as the background for the indicator, giving a LightBox2 effect with a central progress display box. You can find animated GIFs at:

Place your progress element at the top level of the document structure, before other container DIVs. This ensures that when the #progress-overlay is absolutely positioned, it appears above all other content.

<html>
<head>
....
</head>
<body>
<div id="progress-overlay">
    <div id="progress-indicator">
        <img src="images/myprogress.gif" /> Please Wait...
    </div>
</div><!--progress-overlay-->
<div id="website-wrapper">
.... website content goes here ...
</div>
</body>
</html>

The #progress-overlay is initially hidden and displayed when needed, like this:

#progress-overlay{
position: absolute;
width: 100%;
height: 100%;
background: #000;
opacity: 0.2;
}

#progress-indicator{
position: relative;
margin: 0 auto;
top: 40%;
width: 200px;
height: 50px;
}

You can use JQuery to show the progress indicator dynamically:

$(document).ready(function(){
    $('#progress-overlay').hide();
    });
function showProgressIndicator()
{
    $('#progress-overlay').show();
}

Answer №3

In case you are using jQuery, the approach would involve displaying a div containing a message and/or spinner.

jQuery.ajaxSetup({
  beforeSend: function() {
     $('#loader').show();
  },
  complete: function(){
     $('#loader').hide();
  }
});

Answer №4

If you are working with jQuery, here is a suggestion for a solution:

The jQuery code:

$(document).ready(function(){
    $("#click_button").click(function(){
        var url = "controller/method"
        var data = {info: "details"}
        // Show message before sending POST request
        $("#show_message").fadeIn();
        $.post(url, data, function(response){
            if(response.success){
                // If POST request is successful, hide the message 
                $("#show_message").fadeOut();
            }
            else console.log("An error occurred");
        }, 'json');
    });
});

The HTML structure:

<!-- Initially hidden message -->
<div id='show_message' style='display:none;'>
    Please wait.
</div>

The Controller code:

class The_controller extends CI_Controller{
    function the_method(){
        $params = $this->input->post();
        process_task($params);
        if(task_completed_successfully) return json_encode(array("success" => true));
        else return json_encode(array("success" => false));
    }
}

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

Sending a form using Ajax and jQuery

I have created a login form using ajax (jQuery), but I'm facing an issue where the user's email address is not remembered after submission. This means that every time the user logs in, they have to re-enter their full email address instead of it ...

Attempting to integrate information from an external API source

I am struggling with properly formulating a question in order to retrieve relevant search results. I am attempting to extract data from a third-party API (ADP) and store it in my database using asp.net core. My goal is to save the users obtained from the ...

How to implement caching using XMLHttpRequest?

As someone who has primarily relied on jQuery's AjAX method, I am relatively new to using XMLHttpRequests. However, due to performance concerns in a web worker environment, I now find myself having to resort to the classic XMLHttpRequest. Currently, ...

Scrolling to an id within dynamically loaded content using jQuery after an ajax request

After loading content via ajax, I am unable to scroll to the item, as the page remains at the top. Strangely, when I refresh the page dynamically with content caching enabled, the page scrolls to the desired target. var startPageLoader = function( pid, si ...

Storing information in a database using Ajax in the Yii Framework

I am looking to extend the validity of a specific post by updating its toDate field and adding 1 month. Initially, I display all available posts with a button beside each one that, when clicked, triggers the update process. In the code snippet below, clic ...

Is there a method to ensure the month remains unchanged?

In my Laravel project, I am facing a complex condition where I need to set a minimum date for an HTML input of type date. Condition: 1. Users can only select dates from the past ten days. 2. Only two days from the previous month are allowed. For example, i ...

CodeIgniter throwing a date error when it is being hosted

Attention: The date() function may not work properly due to the system's timezone settings. It is essential to specify the date.timezone setting or utilize the date_default_timezone_set() function. If you are still encountering this warning after impl ...

I'm wondering why this isn't working properly and not displaying the closing form tag

What could be the reason for this not functioning properly? The tag appears to close on its own and the closed tag is not being displayed. As a result, the if(isset($_POST['payoneer-btn'])) statement is not triggering. https://i.stack.imgur.com/ ...

The issue of broken images in the Azure Blob module for Drupal

Recently, I began constructing a Drupal website utilizing Azure. I successfully installed the Azure Blob module, and all functions worked flawlessly in my local environment, including image display and upload to storage blob. However, upon migrating the si ...

The model attribute is returned by Ajax

Let me explain the scenario I am facing. Within my controller, specifically in the viewUserReminders method, I am passing remindersListWrapper to the uReminder.jsp page. @RequestMapping(value = "/user/reminders", method = RequestMethod.GET) public Mod ...

A step-by-step guide on incorporating universal CSRF tokens using JQuery AJAX

As part of my development work, I am in the process of creating jquery code that communicates with the server through ajax to input data into a database based on specific request parameters. My main concern at this point is the vulnerability to CSRF attac ...

Loading of local resources is restricted in the Apache web server

I am encountering an issue with my Apache web server on a Raspberry Pi. I need to display graphs using the MPLD3 libraries, which are loaded from the server's folder. When I run my index.php page, I receive a Not allowed to load local resources error ...

jQuery behaving erratically following deployment to the testing server

I am encountering an issue with jQuery in a user control that utilizes a Telerik RadGrid: <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js"></script> <script type="text/javascript"> ...

PHP - Sending a JSON response from a class

I am working with a class: class A { protected $name; public function getName() { return $this->name . " example"; } public function setName($name) { $this->name = $name; } } When I run the following code: $r ...

Technique for dynamically incorporating Csrf tokens prior to every ajax request in CakePHP

I am currently using CakePHP 3.6 and have implemented a function that retrieves data via an AJAX call. This function can be triggered from any page on my website, where a button click opens a modal displaying the data fetched through the AJAX call. The iss ...

Laravel has encountered a delay in processing

After following the instructions in the official Laravel documentation, I successfully installed Laravel on my local machine using both Laravel Installer and composer. However, when I try to access the site from Chrome, I am greeted with an error message s ...

Uploading images simultaneously while filling out a form

Currently, I have a form that requires users to fill it out and upload an image. However, there is a delay of up to 30 seconds when the user hits "Submit" due to the image size being uploaded. I'm interested in finding a way to initiate the image upl ...

Working with the WYSIWYG field in a custom module in Magento

My Magento Module includes a wysiwyg field where I encounter an issue with processing the image path. When using the "Insert image" button in the wysiwyg, it generates the following code: <img src="{{media url=" wysiwyg/slide.jpg"}}" alt=""/> The i ...

Tips for using a JavaScript function to navigate to a specific division (<div>) on an HTML page

I am facing an issue where I need to redirect within the same HTML page that includes a add-form div. What I want is that when I click on a button, my redirection should be to a specific div containing some code. Currently, I have code that redirects to a ...

What steps should I take to refresh my Partial View after a successful form submission?

Greetings, I hope this message finds you well. I have a help page on my website that includes an FAQ section (content served from a Web Service) and a button that displays a partial view. The partial view collects help request information and submits it to ...