I think something like this may work, if response
is just HTML and returns an empty string ''
when there are no more results:
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
var page = 2;
jQuery(function($) {
$('body').on('click', '.loadmorefollowing', function() {
var data =
{
'action': 'user_following_by_ajax',
'page': page,
'security': '<?php echo wp_create_nonce("user_more_following"); ?>',
'author': '<?php echo esc_html($curauth->ID); ?>'
};
$.post(ajaxurl, data, function(response) {
if ( '' === response ) {
$('.loadmorefollowing').hide();
return;
}
$('#following-artists-cont').append(response);
page++;
});
});
});
</script>