Update the body tag when the file input is modified

I am currently working on a webpage called DisplayItems.html that retrieves a list from another page named items.html. I have set it up to refresh its content every few seconds in case items.html is updated. However, I now want to implement a system where DisplayItems checks if the input has changed and only refreshes if necessary. How can I achieve this?

DisplayItems.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link rel="stylesheet" type="text/css" href="Scroll.css">
<script src="jquery1.min.js"></script>
<script type="text/javascript" src="jquery.marquee.min.js"></script>
<script src="jquery-1.12.4.min.js"></script>
<script type="text/javascript">
var jQuery_1_12_4 = $.noConflict(true);
var currentData;
var oldData = jQuery_1_12_4('#text').load("items.html"); 
<!--
function Refresh() {
setTimeout("location.reload(true);");
}
window.setInterval(function CheckForChange(){
  currentData = jQuery_1_12_4('#text').load("items.html"); 
  if (currentData != oldData) {
    currentData = oldData;
    Refresh();
  }
}, 5000);
//   -->
</script> 
</head>
<body  onload="JavaScript:Refresh();">

<ul class='marquee' id="text">
</ul>

<script type="text/javascript">
jQuery_1_12_4('#text').load("items.html");
</script>   
</body>
</html>

Items.html

<li>new item1</li>
<li>senario2</li>
<li>senario3</li>

Answer №1

Perhaps something similar to this approach? Utilizing your existing HTML code (remove the body refresh, and instead incorporate JQuery).

<script type="text/javascript>

    function CheckForUpdates() {

        $.get("/refresh/items.html", function (data) {

            if ($('#content').html() !== data) {
                $('#content').html(data);
                window.setTimeout(CheckForUpdates, 5000);
            }
        });
    }

    $(document).ready(function () {
        Checkforchange();
    });

</script>

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

If the condition is not met, Vue directive will skip rendering the element

I've decided to create my own system for managing roles and rights in Vue since the existing options are not meeting my needs. Currently, I am able to hide an element when a user lacks the necessary role, but what I really want is to completely preve ...

Using jQuery Mobile, load a URL along with its parameters through AJAX

Query I'm facing an issue where I am unable to load linked pages with parameters via Ajax in jQuery mobile. For example, a link like http://www.sampleurl.com/tool.dll?name=first&more=parameters is not loading as expected. Specifics The version ...

Keeping a specific value in a dropdown selection with the help of AngularJS

Is it possible to have a pre-selected {{k.toTime}} initially displayed in the select input? I am having trouble viewing the values of {{k.toTime}} or {{k.fromTime}} as originally set in the select input. The myFormat filter is used to convert minutes int ...

Adjusting Javascript code to convert numerical values in HTML table cells from thousands to millions

Does anyone know how to create a Javascript function for a web report that converts table values to thousands or millions by dividing or multiplying by 1000? The issue is that each value is clickable, meaning it is wrapped in an anchor tag. Is there a wa ...

What is the best way to switch the toggle identifier in order to modify the CSS class "before" using Unicode characters?

I have a compilation of Frequently Asked Questions, accompanied by some custom CSS styling. I am looking to modify the unicode character before each question from a + sign to a - sign, specifically changing content:" \ff0b "; to content:" \002D " ...

Pass SASS/SCSS variables to Javascript without the need to export them to CSS files

Context Let's take a look at the _variables.scss file below: /* Setting up color variables */ $white: #fff; $black: #000; $grey: #ccc; // and so on... // Export the color palette for Javascript accessibility :export { white: $white; ...

How can you utilize the Array submission syntax within HTML coding?

I currently have numerous input fields within a form, and some of them are structured like this: <input name="agents[]" type="file" /> Additionally, imagine there is a plus button next to this field as shown below: <img src="plus.jpg" id="some_ ...

Content not refreshing when closing and reopening Highslide iframe

I am encountering an issue with Highslide where I am unable to reopen a popup with new content. Even though the contentId remains the same, the content is not being updated when the popup is reopened. Below is the code snippet that showcases the problem: ...

Double execution of the Angular customFilter function

My goal is to use a custom filter in Angular to filter an array. Essentially, I have a binding set up like this: {{ myData.winners | getWinnerString }}, which returns an array of items with a length ranging from 1 to 4. If the array consists of more than ...

What is the best way to include a Bootstrap CSS class in a select field using a loop within a Rails application?

Currently, I am dealing with a select field setup in the following way: <%= f.select(:avaliador_id) do %> <% @usuarios_array.each do |u| %> <%= content_tag(:option, u.first, value: u.last) %> <% end %> <% end %> My q ...

Duplicate the checkbox after it has been selected

I am attempting to create a function where a checkbox can be cloned when clicked, with the cloned checkbox starting off unchecked. Once the cloned checkbox is checked, it will then clone itself and the cycle continues. <section ...

What is the best way to showcase JSON keys in Vue.js?

I have a JSON structure that resembles the following: { "data": [ { "name": "someName", "link": "http://somelink.com", ], "relevantArray": [ { "keyIWant": ...

Is there a more "Angular-esque" approach to implementing this (inter-element communication)?

I have created a custom directive that will automatically add an asterisk to the label of any input field marked as required. The following is my link function with detailed comments: // This is what the DOM structure looks like: // <label id="label-1" ...

The mesh's position has become invalid due to the dynamic change in vertices' positions

When attempting to create a mesh using PlaneGeometry, I encountered an issue where after dynamically changing the geometry's vertices, the mesh's position and rotation were no longer correct. Is there a way to update these properties properly to ...

Is it possible to create an If Statement within a foreach loop on an ASP.Net view page?

I am attempting to showcase 4 columns in a single row, with an opening <div class="row"> tag following every group of 4 data elements and a closing tag </div> at the end. @{ int i = 1; } @{ foreach (var item in ViewBag.Prod) { ...

You are unable to establish headers once they have already been sent to the client, as indicated by the error

Github : https://github.com/UJJWAL2001/Pro-Shop/tree/main/backend My current objective is to implement JWT token for securing my routes using the middleware provided below import jwt from 'jsonwebtoken' import User from '../models/userModel ...

We regret to inform you that the local settings were not found. An error has occurred: ModuleNotFoundError - 'account' module

Encountering an issue in cmd: Error message: ModuleNotFoundError: No module named 'account' I am facing a problem with the code below. Do I need to make any changes to the command or the code? https://i.sstatic.net/W8ENh.png import account.fo ...

Converting binary data to a datetime object with AngularJS

Need help converting a date format to the normal date format. For example, from 12-07-2017. Currently, my output looks like this: /Date(1508896907290) I am working with AngularJS. {{list.DateStamp}} Any suggestions on how to convert binary format to ...

What is the best way to activate a click event when I set a radio button to checked?

I am facing an issue with an uninitialized property in my app.component.ts: color!:string; I am trying to automatically initialize the color property when a radio button is selected: <div> <input type="radio" name="colors" ( ...

The Angular ternary operator can be used in conjunction with functions for optimal

Consider this scenario: I have two functions that are triggered by a button click: <button ng-click="functionOne || functionTwo()"></button> However, I want to optimize this setup so that the functions are only called if they return a value. ...