What is the best way to repeatedly make ajax calls from a Java service layer function in order to display page number status?

Script:

function retrievePageStatus(pageNumber) 
{
showMessageHtml('messageDiv', "Retrieving page status for page " + pageNumber);
var url = getURLString(pageForm);
var urlstr = "importTemplate.do?userAction=retrieveStatus&"
        + url.substring(0, url.length - 1);
ajaxFunction();
xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            document.getElementById('messageDiv').style.display = 'none';
            if (xmlHttp.responseText == "success") {
                alert("Page status retrieved successfully for page " + pageNumber);
            } else {
                alert("Error while retrieving page status for page " + pageNumber + ": " + xmlHttp.responseText);
            }
            returnToPageUrl("page?pageId=" + pageId
                    + "&opType=entry&modType=add&menuNavigationId="
                    + menuNavigationId + "&menuPageId=" + pageId);
        }
    }
}
xmlHttp.open("POST", urlstr, true);
xmlHttp.setRequestHeader("Content-Type", "application/plain");
xmlHttp.send(null);
}

I need help in calling the above script repeatedly to retrieve page status based on page number passed from the service layer function. Any assistance would be greatly appreciated.

Answer №1

To make an Ajax call at regular intervals, use the setTimeout(method, frequency) function.

Specify your Ajax call as the 'method' parameter and the time period you want to repeat the call in milliseconds as the 'frequency' parameter.

For example, if your ajax call invokes a servlet, within the servlet retrieve the outputstream of response and write your data:

httpServletResponse.getOutputStream(10);

In your javascript code, you can access the response like this:

xmlHttp.responseText 

Simply display this data on your page.

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 are some effective methods for selectively handling batches of 5-20k document inputs when adding them to a collection containing up to one million documents using MongoDB and Mongoose?

My MMO census and character stats tracking application receives input batches containing up to 5-20k documents per user, which need to be aggregated into the database. I have specific criteria to determine whether a document from the input already exists i ...

Enclose the dollar sign within a span element using jQuery

I want to style any dollar signs $ on my website by wrapping them in a span element. I tried using code that worked for ampersands, but it's not working correctly with dollar signs. Instead of styling the dollar sign inside the paragraph tag, it adds ...

Working with a Mix of Properties in Styled Components

Incorporating a button component with material design using styled-components is my current task. This component will possess various props including size, icon, floating, etc. However, managing the numerous combinations of props has become quite overwhel ...

Send a JavaScript variable to Twig

I am trying to pass a JavaScript variable to a twig path but the current method I am using is not working as expected. <p id="result"></p> <script> var text = ""; var i; for (varJS = 0; varJS < 5; varJS++) { text += "<a href= ...

Is it possible to log out a user in JavaScript by simply removing cookies?

Hey there, I currently have a node.js server running in the background which handles user login processes (I didn't create the backend code). app.use(function (req, res, next) { var nodeSSPI = require('node-sspi'); var nodeSSPIObj = n ...

Preventing the display of developer mode extension pop-ups on Selenium WebDriver automation with ChromeDriver

Currently facing an issue where I keep receiving the alert "Disable Developer Mode Extension" while running automation tests in Chrome. Is there a solution to remove or disable this alert? It's causing me to fail some tests. Thank you in advance. ...

Trouble arises with Webpack during the compilation of JavaScript files

I've been tackling a project in Laravel 5.3, smoothly using webpack until I decided to configure ES6 by adding babel packages to my npm module. This caused a code breakdown, prompting me to revert back to the initial setup. However, now every time I m ...

AngularJS: Enabling unidirectional binding for select option to model

Utilizing a dropdown to display client names. Users have the ability to choose an existing client, which will then update the scope property: Controller Setting up the initial selection. if($scope.clients.length > 0) $scope.existingClient = $scope.cl ...

Sliding with JavaScript

I'm looking to develop a unique web interface where users can divide a "timeline" into multiple segments. Start|-----------------------------|End ^flag one ^flag two Users should be able to add customizable flags and adjust their position ...

Effects with Cleanup - terminates ongoing API calls during cleanup process

Developing a React album viewing application: The goal is to create a React app that allows users to view albums. The interface should display a list of users on the left side and, upon selecting a user, show a list of albums owned by that user on the righ ...

"Printed within the custom directive, the ng model value shows up as undefined

I am currently in the process of creating a custom directive that involves a simple template consisting of an input type textarea. I am assigning the ng-model to ngmodel and creating a link function where I am trying to capture the value of ngmodel. Howeve ...

What is the recommended data type to assign to the `CardElement` when using the `@stripe/react-stripe-js` package in TypeScript?

I'm struggling to determine the correct type to use for this import: import { CardElement } from '@stripe/react-stripe-js'; I have successfully used the types Stripe, StripeElements, and CreateTokenCardData for the stripe and elements props ...

Reviving the Interface: An Overview of Screen Refreshment Following Adjusted Brightness on Android

I am currently working on creating a code that allows the user to adjust the phone's brightness by moving a SeekBar, setting it to the phone's MAIN settings. I believe the issue lies in the following snippet of code: public void onProgressChange ...

What is the process of molding items?

Here is an object that I have: { "id": "Test", "firstname": "Test", "lastname": "Test", "age": 83 } However, I only want to return the object with this value: { "id&quo ...

Obtaining dynamically added control values from the $.ajax callback

Currently, I am developing a master/details style grid using Ajax and JQuery. In the main grid, there is a one-liner with basic information and a "+" sign that can be clicked to expand the row. When expanded, the details are fetched using JSON technology w ...

Disappear gradually within the click event function

I have a coding dilemma that I can't seem to solve. My code displays a question when clicked and also shows the answer for a set period of time. Everything works perfectly fine without the fadeOut function in the code. However, as soon as I add the fa ...

Java: What is the best way to refresh a View after adding a Collection to a Model?

Currently, I am in the process of reworking a program for a professor which involves delving into the Model-View-Controller pattern. The project at hand is GraphViewer, a tool used for designing and visualizing graphs based on Graph Theory (not Statistics) ...

Navigate to an element with a specific ID using JavaScript

How can I implement scrolling to an element on a webpage using pure javascript in VueJS with Vuetify framework? I want to achieve the same functionality as <a href="#link"></a> but without using jQuery. My navigation structure is as follows: ...

Encountering issue with passing ID to Controller via Ajax in Laravel - Error 404 Unresolved

I'm just starting out with Laravel and I'm encountering an error when trying to pass the ID from the view to the controller. POST 404 (Not Found) This is how my View BuffaloMonitor looks like: $(document).on('click', '.viewmoni ...

Should OData or MVC be used to deliver JSON responses?

Currently exploring the use of AJAX for CRUD operations - wondering whether to go with ODATA or MVC. Also considering the integration of JSON in a mobile platform. Appreciate any advice or suggestions. Thanks! ...