2

I have a custom WordPress template page that shows a table and when that table was last updated.

Using jQuery/AJAX, I am attempting to use setInterval() to check every second to see if the update time has changed and auto change the div id element showing the updated time.

I have tried reading tutorials. A lot of them show adding files to the /js/ folder, but my theme does not have that directory.

Looking at the different Wordpress plugins, I was only able to locate ones that showed Javascript across all pages, which isn't what I need.

I currently have a tag (see below) at the bottom of my custom page template. I verified that it loads in the page source.

<script type="application/javascript">
  var update_time_function = window.setInterval(update_time, 1000);
  function(update_time) {
    jQuery.ajax({
      url: 'https://website_url.com/last-update/'
      dataType: 'json'
      success: function(utf) {
        jQuery('#update_time').text(utf[0].date_time);
      }
    })
  };
</script>

The expected results should be the div element with the id 'update_time' should be updating, but it not happening. There are no errors in the network console.

The script file is showing in the page source.

1 Answer 1

1

try updating div data by using jQuery('#update_time').html(utf[0].date_time);

Sign up to request clarification or add additional context in comments.

1 Comment

That does not work either. To do some testing, I added alert('test'); to my script at line one. The alert never appears.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.