I used someone else's code to try to load content into a div on a WordPress home page when a viewer clicked a headline in a list of headlines.
The headlines are all explanatory material on a particular topic. They don't work well as one long piece. I tried using the bootstrap accordion, but some of the sections are much long than others and go too low on the page for that to be an effective strategy. It looks pretty, but readers who were asked for feedback said they didn't think it worked.
AJAX seemed like a good solution; when it works, it looks great. The problem with the following AJAX code is that it works 90 percent of the time on my Firefox browser but not the other 10 percent. I can test it for hours and it's fine. And then I test it again, and suddenly nothing loads in the div. Would anyone be able to explain possible reasons for the failure? Feel free to suggest a better solution. Thank you.
The div:
<div class="col-sm-6" id="mystory-container"></div>
The code:
jQuery(document).ready(function($) {
$.ajaxSetup({cache:false});
$(".mystory-link").click(function(){
var post_link = $(this).attr("href");
$("#mystory-container").html('Loading');
$("#mystory-container").load(post_link);
return false;
});
});