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...
});
Related Posts:
- My javascript is returning this error: $.ajax is not a function
- Can’t get a JSON object in response to an Ajax request with wp_ajax
- Infinite scroll / lazy loading with NextGen Gallery [closed]
- Ajax call does not activate callback function
- Ajax not firing properly using Firefox, but works in Chrome
- How to Use JSON With AJAX?
- Using wp_ajax and wp_ajax_nopriv hooks
- wp_ajax unauthenticated and authenticated
- WordPress ajax function parameter value not being passed
- WordPress customizer refresh screen after save
- Loading posts via AJAX in a hidden div with updated URL?
- Correct way to write jQuery functions in WordPress
- WooCommerce Ajax Cart Update Stopped Working
- How to Dynamically Load Content Into Body of Bootstrap Modal Window?
- Trouble with WordPress Ajax Login System – 302
- videopress videos are not displayed when loading the content with ajax in a lightbox
- How to return multiple arguments from AJAX callback function
- url – ajax loaded but no JS
- Ajax Validation for reCaptcha
- Properly embed javascript into WP (using function.php) – doesn’t work?
- Custom AJAX form not working async
- AJAX Success Function using JS substr() fails in WP 4.1 vs 4.0
- Is there some jQuery conflict here?
- Ajax page load in wordpress the right way?
- Orderby post__in Not Working Correctly?
- Get ajaxForm response value
- Retrieve customizer value using ajax or customizer api and print the value in theme
- Displaying contents of a tab
- Widget won’t work due to old JavaScript? Any ideas how to make it work? [closed]
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Adding images to a Bootstrap Carousel with AJAX
- TypeError: $.ajax(…) is not a function?
- XML Parsing Error: not well-formed in FireFox but good in Chrome
- javascript function wait until another function to finish
- Refresh/reload the content in Div using jquery/ajax
- How to get a cross-origin resource sharing (CORS) post request working
- Download a file by jQuery.Ajax
- ajax stopped working when not logged in?
- Using jQuery to delete data stored in wp_options
- Is there a way to enable Cross-Origin Resource Sharing for WordPress’ ajaxurl?
- How to get attachment id as soon as it is uploaded through media uploader in jquery?
- Using ‘$’ instead of ‘jQuery’ in WordPress
- AJAX call returns 0
- Automatically decrease font size for long words
- jQuery and AJAX Not working with Select Form Element
- How to pass both action and formdata in wordpress ajax?
- Javascript included but alert() function not working
- jQuery Hoverintent plugin in TwentyEleven Menu [closed]
- How wp_enqueue_script works?
- Cannot access elements of json object
- Script won’t execute in the media manager
- Basic ajax call in WordPress
- WordPress AJAX Call Not Return Result
- how to get the comment ID in the front end when the REPLY button is clicked?
- How to create popup same as wordpress popup feature
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Admin wp_ajax hook returning 0
- Is it safe to include a javascript file in a template’s php file?
- Add a Fancybox automatically to post type “post” images
- How to test nonce with AJAX – Plugin development
- JSON output returns page source code [closed]
- Display data on same page as form without refresh
- Dealing with a library that depends on jQuery
- Ajaxify calendar
- start.js:45TypeError: Not enough arguments on Safari [closed]
- Help with a jQuery Carousel
- Passing a varible from jQuery to PHP
- Retrieve post info within AJAX helper function
- Fall Back Google CDN in JavaScript
- I have an old version of jQuery showing up. How do I figure out where it is coming from?
- Search input area autogrow – how?
- Get value of selected option in select field in a WordPress form
- How to retrieve WP_Object that is inside an array of another array
- WordPress Insert not working with ajax
- WP AJAX API with JS file
- admin ajax php success returns 0
- Screen Options JavaScript Code
- Getting jQuery AJAX to work in WordPress (getting -1)
- Theme has superfish – how to add supersubs?
- Which hook to use when adding ajax to viewer-facing side?
- my example with ajax doesn’t work
- Best way to add some custom javascript using jquery to a child theme
- javascript onClick update user_meta from jquery.ajax
- How to use wp_ajax_set_post_thumbnail?
- React to AJAX adding to the page
- Form validation before submitting
- Multiple Notifications SetInterval
- Site images are fixed in front of my site content [closed]
- jQuery not working for media uploader
- How to toggle custom WP archive list
- owl carousel not working after ajax load [duplicate]
- Uncaught TypeError: undefined is not a function (shortcode-box)
- jQuery AJAX add json2 dependency?
- Running javascript in a child theme. Works in jsfiddle
- How to block action if post is “dirty”?
- WordPress video end function [duplicate]
- Ensure an external javascript file called from plugin is loaded after jquery is called
- Why my vertical tab js code is refreshing the page continuously? [closed]
- bootstrap-slider.js by seiyria not working in wordpress