jQuery(document).ready(function($) {
    $('#diyseo_generate_content_button').on('click', function() {
        var postData = {
            action: 'diyseo_generate_content',
            post_title: $('#diyseo_post_title').val(),
            word_count: $('#diyseo_word_count').val(),
            nonce: diyseoMetaBox.nonce
        };

        $.post(diyseoMetaBox.ajax_url, postData, function(response) {
            if (response.success) {
                $('#diyseo_generated_content').html(response.data.content);
            } else {
                alert(response.data);
            }
        }).fail(function(jqXHR, textStatus, errorThrown) {
            console.error("Request failed: ", textStatus, errorThrown);
        });
    });
});
