Guest Posted October 27, 2019 Share Posted October 27, 2019 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> Link to comment
SnazzyView Posted October 27, 2019 Share Posted October 27, 2019 Are you using a template with AJAX enabled? If so try disabling it and seeing if it works. https://support.squarespace.com/hc/en-us/articles/115000253288-Ajax-loading snazzyview.com Link to comment
Guest Posted October 29, 2019 Share Posted October 29, 2019 You were very right. Thanks for the help. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.