Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search

Question

i have an embedded script on my site's homepage that uses JQuery's ready method to execute a function whenever I load my website. The code executes when I load the homepage the first time. But if I navigate to another page on my site and then come back to the homepage, the function won't execute again. How can I fix this?

Here's the code:

<div id="api_text">
  <script>
    $().ready(function() {
      $.get(
        "https://example_url_api.com/",
        function(data) {
          const results = JSON.parse(data.body);

          let print_string = "";
          for (var result_key in results) {
            const result_string = results[result_key];
            $("#api_text").append(result_key + " : ");
            $("#api_text").append(result_value + "<br/>");
            print_string += result_string;
          }
          console.log(print_string);
        }
      );
    });
  </script>
</div>

 

Share this post


Link to post

2 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...