Problem with WordPress Ajax form

Ok, after a lengthy discussion Edegist and I actually sorted this all out. Here’s a couple of the key factors that comprise the solution.

One, we had to loop through all of the selected checkboxes to pass via AJAX.

jQuery( document ).ready( function( $ ) {
    $( '.kvo_ajax_submit_button' ).click( function( e ) {
        e.preventDefault();
        var user_categories = $( 'input[name="user_categories\\[\\]"]' ).map( function() {
            if( $( this ).is( ':checked' ) ) {
                return $( this ).val();
            }
        } ).get();
        var str = {
            'action': 'aj_save_category_settings',
            'security': krv_obj.check_nonce,
            'user_categories': user_categories,
        };
        $.ajax({ 
            type: 'POST',
            dataType: 'html',
            url: krv_obj.ajax_url,
            data: str,
            success: function( data ) {
                // Code after ajax success
                console.log("Success");
            },
            error : function(req, err){
                console.log('Error:' + err);
            }
        } );
    } );
} );

The next step was figuring out why it wasn’t saving to the user_meta database. We realized that the AJAX wasn’t transmitting a $user_id, so we addressed that.

         function aj_save_category_settings( $user_id ) {
          $user_id = get_current_user_id();
            check_ajax_referer( 'krv-nonce', 'security' );
            $krv_user_categories = $_POST['user_categories'];
            if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
            update_user_meta( $user_id, 'user_categories', $krv_user_categories, false );
            wp_die(); // this is required to terminate immediately and return a proper response
        }