JSFiddle - React, Tailwind, and code Playground
by Vasiliy
JavaScript
(function() {
var promoForm = $('.promo-code-form');
if (window.adoric && promoForm) {
$('.promo-code-form').on('submit', function (e) {
var form = $(this);
var code = $('#couponCode').val();
$.ajax({
url: form.attr("action"),
type: "GET",
dataType: "json",
data: form.serialize(),
success: function(res) {
if (res.error && code.toLowerCase() === 'web50') {
adoric.trigger('promoCode');
}
}
})
})
}
})();
//native (not working)
(function() {
document.querySelector('.promo-code-form').addEventListener('submit', function() {
var formData = new FormData(this);
var xhr = new XMLHttpRequest();
xhr.open('GET', this.getAttribute('action'));
xhr.responseType = "json";
xhr.onload = function(res) {
console.log(res);
};
xhr.send(formData);
});
})();