Display a loading image when the button is clicked and the page is loading

I have encountered an issue with my project. I am using two webpages, webpage XXX for input and webpage YYY for output. The processing time takes approximately 2 minutes, so when I click the button on webpage XXX, it displays a white screen until the processing completes and shows webpage YYY.

  1. How can I replace the white blank screen with a loading image that disappears once webpage YYY finishes processing? I have done some research and found this example code:

    function onReady(callback) {
    var intervalID = window.setInterval(checkReady, 60000);
    
    function checkReady() {
    if (document.getElementsByTagName('body')[0] !== undefined) {
        window.clearInterval(intervalID);
        callback.call(this);
           }
       }
    } 
    

The example code is from this site: http://jsfiddle.net/MrPolywhirl/cbLsc81f/

  1. Where should I place the code and CSS to display the loading screen? On webpage XXX or webpage YYY?

I am confused about how to implement the JavaScript in my project. Any assistance would be greatly appreciated.

Thank you in advance.


UPDATE:

This is the code snippet that requests the YYY page from XXX:

public void GenerateReport() 
{

    System.Collections.Specialized.NameValueCollection collections = new System.Collections.Specialized.NameValueCollection();

    collections.Add("ID", Session["ID"].ToString());

    string remoteUrl = "WebfrmReport.aspx";
    string html = "<html><head>";
    html += "</head><body onload='document.forms[0].submit()'>";
    html += string.Format("<form name='PostForm' method='POST' action='{0}' style='display:none;'>", remoteUrl);
    foreach (string key in collections.Keys)
    {
        html += string.Format("<input name='{0}' type='text' value='{1}'>", key, collections[key]);
    }
    html += "</form></body></html>";
    Response.Clear();
    Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");
    Response.HeaderEncoding = Encoding.GetEncoding("ISO-8859-1");
    Response.Charset = "ISO-8859-1";
    Response.Write(html);
    Response.End();
}

Answer №1

Check out the following code snippet for a helpful solution:

<div class="ui-widget-overlay">
    <div id="loadingDivId">
        <img src="~/Content/Images/loading.gif" />
    </div>
</div>

function DisablePage() {
    $('.ui-widget-overlay').css('height', '100%');
}
function EnablePage() {
    $('.ui-widget-overlay').css('height', '0%');
}
$(document).ajaxStart(function () {
    DisablePage();
});
$(document).ajaxStop(function () {
    EnablePage();
    // Redirect to yyy
});
function GenerarteReport() {
    var url = urlHelper.CommonHelper("", "Home", "GenerateReport");
    $.ajax({
        url: url,
        dataType: "json",
        type: "GET",
       contentType: 'application/json; charset=utf-8',
        async: true,
        processData: false,
        cache: false,
        success: function (data) {
            if(data.success)
                alert("success");
            else
                alert("not success")
        }
    });
}

public JsonResult GenerateReport()
{
    System.Collections.Specialized.NameValueCollection collections = new System.Collections.Specialized.NameValueCollection();

    collections.Add("ID", Session["ID"].ToString());

    string remoteUrl = "WebfrmReport.aspx";
    string html = "<html><head>";
    html += "</head><body onload='document.forms[0].submit()'>";
    html += string.Format("<form name='PostForm' method='POST' action='{0}' style='display:none;'>", remoteUrl);
    foreach (string key in collections.Keys)
    {
        html += string.Format("<input name='{0}' type='text' value='{1}'>", key, collections[key]);
    }
    html += "</form></body></html>";
    Response.Clear();
    Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");
    Response.HeaderEncoding = Encoding.GetEncoding("ISO-8859-1");
    Response.Charset = "ISO-8859-1";
    Response.Write(html);
    Response.End();
    return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}

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

What is the simplest method for connecting to an SSH session on a Windows device?

My task involves developing an application on a Windows machine, which is necessary due to the nature of the work it already performs. This app needs to interact with two separate Tandberg units simultaneously via ssh. I will be monitoring their console ...

When coding in JavaScript, the value of "this" becomes undefined within a class function

I'm facing an issue with my TypeScript class that contains all my Express page functions. When I try to access the class member variable using this, I get an 'undefined' error: class CPages { private Version: string; constructor(ver ...

Investigate issues with POST data requests

I recently utilized a REST API to send a POST request. Upon clicking on the function addmode(), a textbox is displayed allowing users to input data. However, upon clicking the save() button, an unexpected error occurs and redirects to a PUT Request. Using ...

Can a person select a characteristic like "height" using Javascript?

Is it doable to set a height for an image in CSS, then detect this gradient using JS and double the width based on the height x2.25? Could this be achieved? ...

Discovering the selected div in Angular is a common task that can be

I am looking to determine which div is currently selected. Please review my code: <divdsadsadasda toggle(i) { console.log(i) // the index has been obtained } I am trying to identify the selected div and retrieve values from the clicked item. ...

Converting data from Random.org into an integer using JavaScript

I have been working on a small web application to experiment with CSS animations. Although it's functioning, I'm seeking more genuine randomness. To achieve this, I am exploring the use of Random.org. How can I import the output from Random.org i ...

Leveraging enum type within interface in C#

One of the classes in my project has a method called GetSomething that returns an IEnumerable: protected virtual IEnumerable<T> GetSomething(CrudOptions crudOptions) { ... } CrudOptions is defined in myProject.Enums namespace as: namespace myP ...

Challenges with conditional statements in JavaScript

This is a simple code snippet for a ToDo-List application. The function InputCheck() is designed to validate if the input bar contains any value. If the input bar is empty, the function should not trigger the addTodo function. However, in its current stat ...

What is the best way to retrieve an object from every function?

I'm dealing with a <div> containing radio buttons: <div id='RB-01'> <span>Item_1</span><input type='radio' name='RB01' value='1'><br /> <span>Item_2</span><inp ...

Using JavaScript to populate an input field with a value

I am having an issue with a Javascript code that is supposed to update a form input value, but for some reason it is not working as expected. Below is the code in question: <script> function up2(mul) { var passcode = parseInt(document.getElementById ...

Select an <li> element from div1 and move it to div2 when a button is clicked

Even though I have experience with JavaScript, I am struggling to figure out a simple task. Here is the list of items I need help with: <div id="left-side"> <ul> <li><div>Item 1</div></li> <li> ...

Primary term in the JSON response of an API

My API response includes a JSON object like this: { "timestamp": 1372741243, "base": "USD" } I want to make a call to this API using the following code snippet: HttpResponseMessage response = client.GetAsync("api/latest.json?app_id=your_api_id").Res ...

struggling with typing an object in react typescript - Element is assumed to have an 'any' type due to its type

Having trouble with the code snippet below: // if I remove the `any` below it breaks. const teams: any = { liverpool: <Liverpool />, manUtd: <ManUtd />, arsenal: <Arsenal />, }; export const TeamCrest = ({ team }: { team: ke ...

Tips for downsizing a large image to fit into a smaller area

I am working on a page layout that features a small circular navigation element. However, I am facing an issue with fitting a large picture within the boundaries of this small circle without it overflowing and causing alignment problems. Does anyone have ...

Executing an onEdit script exclusively on specific sheets

As a beginner in coding Scripts, I have successfully managed to modify a script that adds a custom timestamp onEdit. It inserts the timestamp into the cell next to where the edit occurred, targeting columns 3 and 6 with an offset of -1. The workbook now c ...

Executing a JavaScript function within HTML on the server side using Node.js

Recently, I've been working with an index.html file that references a CircleArea.js script. The HTML code looks like this: <!DOCTYPE html> <html> <head> <title>Server-side Example</title> <script sr ...

Enhance your webpage with a dynamic form feature for adding multiple products using jQuery

I'm currently working on a project to develop a dynamic form that includes both input fields and dropdown menus populated with data from a JSON file (for now, I'm using an array). The form should also have the functionality to "add another produc ...

Is there a distinction between "muted" and "volume = 0.0"? Event listeners handle them in separate ways

I am a newcomer to coding and have encountered an issue that has me stumped. I am working on developing a small media player intended for use with the athletes I coach. The concept is to require them to listen to my commentary while watching game footage. ...

Error with Ant Design Autocomplete functionality when searching for a number

I am currently using ant design to develop a more advanced autocomplete component that will display data from multiple columns. In this particular scenario, I have two columns named tax_id and legal_name that users can search by. Everything works smoothly ...

Accessing the identical file concurrently through ajax 12 times

I'm facing an issue with loading the same external file multiple times on a page. When the page loads, it takes up to a minute due to large load times. I've tried using Ajax to load each file individually, but running a loop to load all files at ...