Trying to get single posts to load on the front page via ajax

The difference between the code you linked and your version, is that your post link has the permalink as the href value, where the original has just a hash. When you add a click handler to an anchor tag, it doesn’t prevent what normally occurs when you click that link, it just executes the javascript and normal link behavior continues as it otherwise would. If you want to prevent links from being followed on a click event, you have to explicitly prevent that in your javascript:

$(".post-link").click(function(event) {
    event.preventDefault();
    // the rest of your code... 
});

Leave a Comment