Using Ajax for updating table content on a JSP webpage section

I am working on implementing Ajax functionality for a table to enable partial updates every hour. Below is a snippet of my JSP code:

  < head >
    < meta http - equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
    < title > Insert title here < /title>

     </head >

  < body >

< jsp: useBean id = "bs" class = "beam_Status.BeamStatus_Bean" > < /jsp:useBean>

 < br >
  < h1 > Total Beamlines open are $ { bs.total_Beamopen()} < /h1>

<CENTER><H1>BEAMLINE STATUS</H1 > < /CENTER>
   <center>
<table  border = "1" cellpadding="1" width="750px" id="ajax"> 
  
     <tr> 
      <th><h1><b>BEAMLINES</b > < /h1></th >
      < th > < h1 > < b > STATUS < /b></h1 > < /th> 
      <th><h1>SYMBOLIC REPRESENTATION</h1 > < /th>
    </tr >

  <c:forEach var = "country" items = "${bs.beam_CurrentStatus()}">
    <h3><b>
      <c:choose>
        <c:when test = "${country.value == 'IN OPERATION'}">
          <tr>
            <td class = "green" style = "text-transform: uppercase;" width = "400px"><center><h1>$ { country.key }</h1></center></td> 
            <td class="green" style="text-transform: uppercase;" width="300px"><center><h1>${country.value}</h1></center></td>
            <td width="200px"><center><img src="red.png" align="middle" width="100" height="110" /></center></td>
          </tr> 
        </c:when>
        <c:otherwise>
          <tr>
            <td class="red" style="text-transform: uppercase;" width="400px"><center><h1>$ { country.key }</h1></center></td>
            <td class="red" style="text-transform: uppercase;" width="300px"><center><h1>${country.value}</h1></center></td>
            <td width="200px"><center><img src="green.png" align="middle" width="100" height="110" /></center></td>
          </tr> 
        </c:otherwise>
      </c:choose>
    </b></h3>
  </c:forEach>

  </table>
  
</center>

Currently, the entire page refreshes due to the usage of:

<% response.setIntHeader("Refresh", 5); %>

I am new to Ajax and would appreciate any guidance on how to implement it in this context.

Answer №1

Key concept:

function receiveData () {
  var content = this.responseText;  //The server will only send back the updated HTML for the table
  document.getElementById("tableContainer").innerHTML = content;  //Specify the element wrapping the table to be replaced
}

var request = new XMLHttpRequest();
request.onload = receiveData;
request.onerror = function(){alert("Oops, an error occurred!");};
request.open("get", "scriptToFetchTable.php", true);
request.send();

Stay informed about the tools you are employing.

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 proper way to utilize $apply and $watch in the Angularjs 1.4.10 Directive Structure?

`.directive('counter', function counter() { return { scope: {}, bindToController: { count: '=' }, controller: function () { function increaseCount() { this.count++; } function decreaseCo ...

Accessing PHP variables within a React componentTo access external

How can I pass the id selected in a menu from a react component to a PHP file, after already knowing how to send data from PHP to the react component? $.ajax({url: '/file.php', type: 'POST', dataType: 'json', ...

Angular2 Error: Cannot have two identifiers with the same name, 'PropertyKey' is duplicated

I am currently developing an application with angular2 using angular-cli. Unfortunately, angular-in-memory-web-api was not included by default. After some research, I manually added the line "angular-in-memory-web-api": "~0.1.5" to my ...

Guide on displaying an array object in MongoDB using React

I'm having trouble figuring out how to display certain data from my MongoDB schema in a React component. Here is my MongoDB schema: const postSchema = new mongoose.Schema({ userID: { type: String }, dateTime: { type: Date, default: Date.now } ...

"Encountering issues with AJAX sign up feature on Devise platform

Currently, I am working on setting up a registration form with the help of devise and AJAX. While it functions perfectly on a freshly generated application, I have been struggling to integrate it into an existing project. Here are some links to key compon ...

Using JQuery toggleclass to add transitioning effects to a :after element

I'm using the toggleClass function to add the class .expend to a div with an ID of #menu, which increases the height of the menu from 100px to 200px with a smooth transition effect. I also have a pseudo-element #menu:after for aesthetic purposes. My ...

Utilizing Jquery Ajax calls to populate a user list on project selection

I am currently utilizing Jira and in need of populating the list of users for the selected project. <td><select id="projectsList" class="textFld" multiple="multiple"></select></td> <td><select id="userList" class=" ...

How to effectively use the LIKE statement in mysql with node.js

app.post('/like/:level/:name', function(req, res){ connection.query("SELECT * from books where " + req.params.level + " like '%" + req.params.name + "'%", function(err, rows, fields) { if (!err){ var row = rows; res.send(row); console.l ...

Utilizing an object as a prop within React-router's Link functionality

Looking for a solution to pass the entire product object from ProductList component to Product component. Currently, I am passing the id as a route param and fetching the product object again in the Product component. However, I want to directly send the ...

Router-view failing to display component

I am currently working on setting up basic routing in Vue. I have identified three file listings that seem to be causing issues. When I include <router-view> in app.vue, the foo component appears in the browser. However, when I follow the instruction ...

Beware: The use of anonymous arrow functions in Next.js can disrupt Fast Refresh and lead to the loss of local component state

I am currently encountering a warning that is indicating an anonymous object in a configuration file, and even specifying a name for it does not resolve the warning. Below you will find the detailed warning message along with examples. Warning: Anonymous ...

Pressing the button will allow you to select and copy the text within the

I am looking to incorporate a mock-chat feature into my website. The concept is to type something on the website, then click a button next to it which will move the text to a frame above. I attempted this using a textarea and even found a code for selectin ...

I'm baffled on how to find access to ParametricGeometry within Three.js

I've been looking into how to access ParametricGeometry because I keep encountering this message when I attempt to use it: "THREE.ParametricGeometry has been relocated to /examples/jsm/geometries/ParametricGeometry.js" Any ideas on how to do this wou ...

Implementing a function when a grid's action column is clicked

I am facing an issue with a yii grid that includes an action column with custom buttons. I want to call a function when one of the buttons is clicked, but I keep getting an error. Here is the code snippet: [ 'class' => 'kartik&b ...

Solving repeated function firing with ng-checked in an AngularJS ng-repeat loop

In the HTML code below, there is an ng-repeat that creates checkboxes: <span ng-repeat="name in $ctrl.widgetSelectorNames" class="widget-selectors"> <label class="checkbox" for="{{name}}"> <input type="checkbox" value="{ ...

Break down for me what Json is in a way that a five-year-old could understand

Let me clarify one thing, I may not be a Javascript expert but I'm far from being 5 years old. Json is one concept that's been confusing me lately as I dive into the world of programming. Can someone please explain json to me in a simplified mann ...

Is it possible to display two separate pieces of content in two separate divs simultaneously?

import React from "react"; import ReactDOM from "react-dom"; ReactDOM.render( <span>Is React a JavaScript library for creating user interfaces?</span>, document.getElementById("question1") ) ReactDOM.render( <form class="options"> ...

One typical approach in React/JavaScript for monitoring the runtime of every function within a program

Experimenting with different techniques such as performance.now() or new Date().getTime() has been done in order to monitor the processing time of every function/method. However, specifying these methods within each function for time calculation purposes h ...

Is there a way to retrieve the parameter data from the previous post that isn't displayed in the URL?

Utilizing AJAX in jQuery, I send a parameter to the URL when a selection is made in a combobox with the following script: $('#plant').change(function(e2){ $('#location').html('<img src="02_files/01_images/loading.gif">' ...

Transforming the appearance of an Imagebutton upon clicking with the power of Javascript

I am attempting to update the image URL when a specific image button is clicked, however, I am encountering an issue where the image does not change. It seems that none of the JavaScript functions are successfully altering the image and are unable to iden ...