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