Call Us

(833) 697-3493

document.addEventListener('DOMContentLoaded', function () { // Select the JetForm form using its class or ID const jetForm = document.querySelector('.jet-form-builder'); // Update the selector if necessaryif (jetForm) { jetForm.addEventListener('submit', function (event) { event.preventDefault(); // Prevent the default form submission behavior// Get the MC Number from the input field (assuming input name is 'mc_number') const mcNumberInput = jetForm.querySelector('input[name="mc_number"]'); const mcNumber = mcNumberInput ? mcNumberInput.value : '';if (mcNumber === '') { alert('Please enter an MC number.'); return; }// Define the n8n webhook URL const webhookUrl = 'https://n8n.reize.cc/webhook/agreement';// Send the MC Number to n8n via an AJAX POST request using Fetch API fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mc_number: mcNumber }) }) .then(response => response.json()) .then(data => { // Log the response for debugging console.log('Response from n8n:', data);// Redirect to the URL provided by n8n if available if (data && data.redirectUrl) { window.location.href = data.redirectUrl; // Redirect the user } else { alert('Unexpected response. Please try again.'); } }) .catch(error => { console.error('Error during AJAX request:', error); alert('There was an error processing the request. Please try again.'); }); }); } });