jQuery(document).ready(function($) {
    $('#diyseo_generate_meta_description').on('click', function() {
        var data = {
            action: 'diyseo_generate_meta_description',
            post_id: diyseoMetaParams.postId,
            nonce: diyseoMetaParams.nonce
        };
        $('#diyseo_meta_description_loading').show();
        $.post(ajaxurl, data, function(response) {
            $('#diyseo_meta_description_loading').hide();
            if (response.success) {
                $('#diyseo_meta_description').val(response.data);
                location.reload(); // Reload the page to show the saved meta information
            } else {
                alert('Failed to generate meta description.');
            }
        });
    });
});