const key = "9ADVXhVOVVmaSt2VzhWbh9EdtdFdxATYXFzVUdXTtVmTGRVUxxmROpmUrRlc1AjUhBXbUhUNFVmSKR1V"; var visitorId; $("#form-teste").on("submit", function (e) { e.preventDefault(); // cancel the actual submit var planoId = $("input[name=adult]:checked").val() ? 8 : 806; var payload = { nome: $("#inputName").val(), email: $("#inputEmail").val(), plano: planoId, user_id: visitorId, }; $.ajax({ url: "//cliente.kudaplay.cf/gerador?k=" + key, type: "post", data: JSON.stringify(payload), dataType: "json", contentType: "application/json", beforeSend: function () { $("#btn-envia").attr("disabled", "disabled").html("Aguarde..."); }, success: function (data) { if (typeof data == "object") { if (data.sucesso == false) { if (data.mensagem != null) { Swal.fire({ title: "Atenção", text: data.mensagem, icon: "error", confirmButtonText: "Entendi", }); } else if (isArray(data.erros)) { var msg = ""; for (var i = 0; i < data.erros.length; i++) { if ( data.erros[i].property_path != null && data.erros[i].error_message != null ) { msg += "[" + data.erros[i].property_path + "] : " + data.erros[i].error_message + "\n"; } } if (msg.length > 0) { Swal.fire({ title: "Atenção", text: msg, icon: "error", confirmButtonText: "Entendi", }); } } $("#btn-envia") .removeClass("btn-success") .addClass("btn-alt-primary") .removeAttr("disabled") .html("Tentar novamente"); } else { $("#btn-envia") .removeClass("btn-alt-primary") .addClass("btn-success") .html("Vai assistir :D"); Swal.fire({ template: "#swal-template-success", }); } } else { Swal.fire({ title: "Atenção!", text: "Bip, bip! Algo de errado não está certo!", icon: "error", confirmButtonText: "Entendi", }); $("#btn-envia") .removeClass("btn-success") .addClass("btn-alt-primary") .removeAttr("disabled") .html("Tentar novamente"); } }, error: function (xhr, statusText, err) { const data = xhr.responseJSON; if (typeof data == "object" && data.sucesso == false) { if (data.mensagem != null) { Swal.fire({ title: "Atenção", text: data.mensagem, icon: "error", confirmButtonText: "Entendi", }); } else if (isArray(data.erros)) { var msg = ""; for (var i = 0; i < data.erros.length; i++) { if ( data.erros[i].property_path != null && data.erros[i].error_message != null ) { msg += "[" + data.erros[i].property_path + "] : " + data.erros[i].error_message + "\n"; } } if (msg.length > 0) { Swal.fire({ title: "Atenção", text: msg, icon: "error", confirmButtonText: "Entendi", }); } } $("#btn-envia") .removeClass("btn-success") .addClass("btn-alt-primary") .removeAttr("disabled") .html("Tentar novamente"); } else { Swal.fire({ title: "Atenção!", text: "Bip, bip! Algo de errado não está certo!", icon: "error", confirmButtonText: "Entendi", }); $("#btn-envia") .removeClass("btn-success") .addClass("btn-alt-primary") .removeAttr("disabled") .html("Tentar novamente"); } }, }); }); // $( window ).on( "load", function() { // $("#inputName").focus(); // }); function isArray(what) { return Object.prototype.toString.call(what) === "[object Array]"; } function initFingerprintJS() { // Initialize an agent at application startup. const fpPromise = FingerprintJS.load(); // Get the visitor identifier when you need it. fpPromise .then((fp) => fp.get()) .then((result) => { // This is the visitor identifier: visitorId = result.visitorId; }); }