rl-warmup-plugin/js/generate-conversation.js
2025-01-15 10:49:39 -06:00

36 lines
1.4 KiB
JavaScript

jQuery(document).ready(function ($) {
$('#generate-conversation').on('click', function () {
const initiatedBy = $('#initiated_by').val();
const subject = $('#subject').val();
const length = $('#length').val();
$.ajax({
url: rlGenerateConversation.ajax_url,
type: 'POST',
data: {
action: 'rl_generate_conversation',
nonce: rlGenerateConversation.nonce,
post_id: rlGenerateConversation.post_id,
initiated_by: initiatedBy,
subject: subject,
length: length,
},
beforeSend: function () {
$('#generate-conversation').text('Generating...').prop('disabled', true);
},
success: function (response) {
$('#generate-conversation').text('Generate Conversation').prop('disabled', false);
if (response.success) {
console.log('Conversation generated successfully! ID: ' + response.data.conversation_id);
} else {
alert('Error: ' + response.data.message);
}
},
error: function () {
$('#generate-conversation').text('Generate Conversation').prop('disabled', false);
alert('Failed to generate conversation. Please try again.');
},
});
});
});