rl-warmup-plugin/js/generate-timeline.js

36 lines
1.4 KiB
JavaScript

jQuery(document).ready(function ($) {
$('#generate-timeline-button').on('click', function (e) {
e.preventDefault();
const postId = $('#post_ID').val();
$('#generate-timeline-result').html('<p>Generating timeline...</p>');
$.ajax({
url: rlMailWarmerGenerateTimeline.ajax_url,
method: 'POST',
data: {
action: 'rl_mailwarmer_generate_timeline',
post_id: postId,
security: rlMailWarmerGenerateTimeline.nonce,
},
success: function (response) {
console.log(response);
if (response.success) {
const timeline = response.data;
let output = '<p>Timeline Generated:</p><ul>';
$.each(timeline, function (date, volume) {
output += `<li><strong>${date}:</strong> ${volume} emails</li>`;
});
output += '</ul>';
$('#generate-timeline-result').html(output);
} else {
$('#generate-timeline-result').html('<p>Error: ' + response.data + '</p>');
}
},
error: function (xhr, status, error) {
$('#generate-timeline-result').html('<p>AJAX Error: ' + error + '</p>');
},
});
});
});