You can easily add whatever variables you want to your AJAX call.
Using jQuery you can set a AJAX action like this:
jQuery.post(
'your-url-to-admin-ajax.php',
{
action: 'your_called_function',
argument: 'year' or 'category',
some_other_var: 'some value'
},
function( response ) {
if(response) {
} else {
}
}
);
Then in your functions.php add this:
add_action( 'wp_ajax_nopriv_your_called_function', 'your_called_function' );
add_action( 'wp_ajax_your_called_function', 'your_called_function' );
function your_called_function() {
$argument = $_POST['argument'];
$otherVar = $_POST['some_other_var'];
// now you can do the loop with your argument
// important to add exit(), or it won't work
exit();
}
In detail here: http://www.makeuseof.com/tag/tutorial-ajax-wordpress/