How can JQuery be used to implement "scrolling" buttons and automatically update the main page with fresh data?

I am attempting to achieve the following:

  • 1 - Use jQuery to update index.html with the content from output.html (only update when there are differences in data, and ideally only update the parts that have changed).

  • 2 - Add two buttons in the header labeled "Left" and "Right" for scrolling left and right across a table.

I have made several attempts to make it work but so far have been unsuccessful. Below is an example of my attempt at step 1 (updating index.html with new content from output.html)

Main HTML (index.html) calling Secondary HTML (output.html)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Website</title>
    <style type="text/css">
        <!-- @import url("nstyle.css");
        -->
    </style>
    <script>
        update_content()
         $(document).ready(function (e) {
            var refresher = setInterval("update_content();", 250);
        })
        function update_content() {
            $.ajax({
                type: "GET",
                url: "testoutput.html",
                timeout: 10000,
                cache: false,
            })
                .done(function (page_html) {
                    var currentDoc = document.getElementById("container");
                    if (page_html != currentDoc.innerHTML) {
                        var newDoc = document.getElementById("container");
                        newDoc.innerHTML.write(page_html);
                        newDoc.close();

                    }
                });
        }
    </script>
</head>
<body>
    <div id="header_container">
        <div id="header">
            <a href="http://website.com/" target="_blank">
                <img src="logo.png">
            </a>
        </div>
    </div>
    <div id="container"></div>
    <div id="footer_container">
        <div id="footer">
            <a href="http://webiste.com/" target="_blank">
                <img src="logo.png">
            </a>
            <div id="footer1">
                <i>Copyright &copy; 2013 <a href="http://website.com/" target="_blank"><font color=blue>Website</font></a>.</i>
            </div>
            <div id="footer2">
                <i>All Rights Reserved.</i>
            </div>
        </div>
    </div>
</body>
</html>

Secondary HTML (output.html)

    <table id="gradient" summary="">
...
(Original code continues)

CSS Snippet

(CSS styling details here)

Function That Generates the Original HTML Page

(Python code generates HTML tables based on provided data)

data Variable Example:

(Example data used in Python function)

If anyone has any suggestions or can provide assistance with this issue, it would be greatly appreciated. I will add a bounty to this post in two days as a token of gratitude.

Answer №1

Consider implementing the following approach:-

To optimize the process of updating new content in "newoutput.html", separate the server-side script responsible for generating HTML files for this purpose from the one handling "output.html". Utilize two distinct functions: one to load the entire document (output.html) and another to update specific elements at intervals of 250 milliseconds. By doing so, you can reduce the workload by only modifying the necessary table within the HTML document every 250 milliseconds. The "output.html" can contain the complete HTML structure (<html>..</html>), while the second script should focus on writing the snippet of innerHTML inside #container (assuming

<div id="container"><table id="gradient" summary=""></table></div>
) into "newoutput.html"


The content of newoutput.html generated by createNewOutput.php: -


(Table content here)

Afterward, make adjustments to your JavaScript code:


load_content() //function to load output.html
$(document).ready(function (e) {
    var refresher = setInterval(function(){update_content();}, 250);
})

function update_content()
{
$.ajax({
url: 'createNewOutput.php',
success:function(){
$.get('newoutput.html',function(data)
{
if(data!=$('body #container').html())
{
$.when( $('body #container').empty().append(data) ).then(

//Add CSS styling if necessary for dynamically added content

#gradient.css({
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
margin: 0px;
width: 100%;
text-align: center;
border-collapse: collapse;
});

) 
} 
}) 
} 
})
}

If the changes are limited to specific elements, such as data in the second row of a table, consider having the server-side script return a subset of data (e.g., JSON or plain text), which can be parsed and compared with the innerHTML of targeted elements.

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

Lost in a strange predicament

As I try to send props from my parent component to the child component, I am facing an issue where one of the children within the coin prop seems to be lost when I receive the props in componentWillReceiveProps(). This discrepancy becomes evident through t ...

A variable in Javascript storing data about jQuery DOM elements

Currently, I am using the slick slider for my development (http://kenwheeler.github.io/slick/) In JavaScript, there is an event that returns a variable called 'slick' When I print the variable using console.log, this is what I see: From what I ...

Using Twitter Bootstrap and jQuery UI modal within an mvc4 framework

I successfully integrated jQuery UI scripts for modal and datepicker into the generic MVC4 template view. However, when I tried to include Twitter Bootstrap layout as well, the datepicker and modal elements were not displaying properly. Additionally, I enc ...

What is causing the scripts to fail when I attempt to press a button?

Clicking on the button is supposed to slowly reveal phone numbers on the page. Here are the HTML Codes: <span id="show-phone-numbers" class="btn btn-success"> <i class="fe fe-phone-call"></i> Show Phone Nu ...

Display the option to "Delete" the link only when there are multiple images in my image collection

I am using jQuery and Ajax to remove banner images from my website. However, I want to make sure that if there is only one image left, it cannot be deleted. Each image in the list has a corresponding delete link: echo '<a class="delete j_bannerd ...

Exploring AngularJS 1.x: Understanding the differences between isolated scope and using require with ngModel

Throughout my experience with Angular 1.x, I have always used isolated scope in my directives. However, recently I encountered a directive that solely utilized ngModel. This made me curious about the differences and potential issues when using both methods ...

Adjusting the transparency of the background color seamlessly without the need for an image

After creating a div element with a green background color, I am looking to progressively change the opacity of the color from top (darkest green) to bottom (lightest, white). Is there a CSS-based way to achieve this effect without resorting to using an ...

"Exploring the world of TypeScript Classes in combination with Webpack

If I create a TypeScript class with 10 methods and export a new instance of the class as default in one file, then import this class into another file (e.g. a React functional component) and use only one method from the class, how will it affect optimizati ...

Having trouble retrieving the value of a custom directive attribute

My custom directive, named "mycomponent", has the following configuration: restrict: 'AE', templateUrl: 'template.html', scope:{ sTransactionType: '=transactionType', sStorageVariable: '=storageVariable&apos ...

Changing a DOM structure into pure HTML using JavaScript

Looking to convert some HTML into a PDF file using a service that requires form-data as the payload. Is there a way to extract HTML from the DOM and save it as a file for use in the payload? <p>some other HTML</p> <div id="content"> ...

The module "jquery" in jspm, jQuery, TypeScript does not have a default export

Having some trouble setting up a web app with TypeScript and jspm & system.js for module loading. Progress is slow. After installing jspm and adding jQuery: jspm install jquery And the initial setup: <script src="jspm_packages/system.js"></scri ...

How can we ensure that the borders of a text field automatically adjust to fit the dimensions of the text field using CSS?

I've encountered an issue with the borders of text fields while working on a project involving CSS/HTML. The problem is that in the browser, the borders appear shorter than the text fields. Initially, I attempted to adjust the border size to match th ...

What might be causing my direct descendant selector to not work as expected?

I'm struggling with my direct descendant selector. Let's analyze a straightforward example: .myDiv > table tr:first-child td { font-weight: bold; text-align: center; } <div class="myDiv"> <table style="width:100%"> < ...

Priority is given to strings over numbers

Here's some code I'm working with: <tbody> <tr> <td class="float-left"> <!-- {{selectedTemplat?.modifiedAt | da ...

Tips for ensuring session token verification remains intact upon reloading

I am currently in the process of developing a website using the Next.js framework and I am seeking advice on how to prevent the reload effect that occurs when transitioning from the login page back to the main page for just a fraction of a second. Below i ...

What is the best way to reference the className within nested SCSS when working with Next.js and React.js?

I am working on customizing a navbar that includes a hamburger button. My goal is to change the style, specifically the bar color and the appearance of the hamburger button, upon tapping. I have already attempted using &:active and .activeBar in the SCSS f ...

Is there a way to retrieve all the selected values from multiple select inputs when a button is clicked in React?

I am currently working on developing a questionnaire where the select inputs' values are collected and averaged to generate a final score. Although it may sound simple, I'm facing difficulties in retrieving these values. At this point, my primary ...

The spacing of the numbers in Highcharts is too cramped

Is there a solution to make close values like 16 and 16.5 readable in Highcharts? I couldn't find an answer in the documentation. http://jsfiddle.net/01Lquzrm/ $(function () { $('#container').highcharts({ chart: { t ...

Issues with Wordpress Ajax request on customized page are causing functionality to fail

Everything appears to be in order, but I am still unable to populate the destination. So far, I have confirmed that the PHP and JS files within my plugin are being located and can even generate output in XML. This is evident when observing the default beh ...

What is the best way to position two divs side by side while maintaining their individual padding?

When I remove the padding as shown, the website functions correctly with two div columns next to each other. However, upon adding padding, the #right div shifts downwards. How can I ensure it works as intended with padding included? HTML: Two divs direct ...