Add Fade effect for ajax loading content in WordPress


In wordpress site while you add ajax function to modify html content you can do it in fancy way like adding some jquery effect. so user can see updated contents in site.

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('.ajaxlink').click(function(e) {
        e.preventDefault();
        var postid = jQuery(this).data('postid');
        jQuery.ajax({
            type: 'POST',
            url: "http://your-wordpress-site.com/wp-admin/admin-ajax.php",
            data: {
                action: 'action_show-post-extra-content',
                postid: postid
            },
            success: function(data) {
	        //show ajax output with fade effect
                jQuery(".ajax-output-div").hide().html(data).fadeIn();
            }
        });
    });
});
</script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s