# mxchat-basic/1.4.2/js/activation-script.js

MxChat – AI Chatbot &amp; Content Generation for WordPress, version 1.4.2. 62 lines.

- Page: https://pluginprobe.com/plugins/mxchat-basic/1.4.2/code/js/activation-script.js
- Raw: https://pluginprobe.com/plugins/mxchat-basic/1.4.2/raw/js/activation-script.js
- Modified: 2024-11-14T16:22:08+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/mxchat-basic/1.4.2/code/js/activation-script.js#L10-L20`.

```javascript
document.addEventListener('DOMContentLoaded', function() {
    var form = document.getElementById('mxchat-activation-form');
    var spinner = document.getElementById('mxchat-activation-spinner');
    var submitButton = document.getElementById('activate_license_button');
    var licenseStatus = document.getElementById('mxchat-license-status');

    form.addEventListener('submit', function(e) {
        e.preventDefault();

        // Show spinner and disable the button to prevent multiple submissions
        spinner.style.display = 'inline-block';
        submitButton.disabled = true;

        // Gather form data
        var formData = new FormData(form);
        formData.append('action', 'mxchat_activate_license');
        formData.append('security', mxchatData.nonce);

        // Send the AJAX request
        var xhr = new XMLHttpRequest();
        xhr.open('POST', mxchatData.ajax_url, true);
        xhr.onload = function() {
            // Hide the spinner
            spinner.style.display = 'none';

            if (xhr.status >= 200 && xhr.status < 400) {
                var response = JSON.parse(xhr.responseText);
                if (response.success) {
                    // Update the license status to active
                    licenseStatus.textContent = 'Active';
                    licenseStatus.classList.remove('inactive');
                    licenseStatus.classList.add('active');

                    // Hide the activation form
                    form.style.display = 'none';
                } else {
                    // Re-enable the button
                    submitButton.disabled = false;

                    // Handle the error case
                    alert(response.data || 'There was an error activating the license.');
                }
            } else {
                // Re-enable the button
                submitButton.disabled = false;

                // Handle server error
                alert('Server error. Please try again.');
            }
        };

        xhr.onerror = function() {
            // Hide the spinner and re-enable the button on error
            spinner.style.display = 'none';
            submitButton.disabled = false;
            alert('Request failed. Please check your internet connection.');
        };

        xhr.send(formData); // Send the form data
    });
});

```
