function SubmitData (data) {
// Проверка включена ли grecaptcha в настройках
if ($('#grecaptcha').length > 0) {
$.getScript('https://www.google.com/recaptcha/api.js?render=SITEKEY', function() {
grecaptcha.ready(function() {
grecaptcha.execute('SITEKEY', {action: '123'}).then(function(token) {
console.log('111');
});
});
});
}
console.log('222');
$.ajax({
type: "POST",
url: address,
data: $(formId).serialize(),
contentType: "application/x-www-form-urlencoded",
dataType: "text",
success: function (data) {
}
});
}
async function SubmitData(data) {
let captchaToken;
// Проверка включена ли grecaptcha в настройках
if ($('#grecaptcha').length > 0) {
captchaToken = await getCaptchaToken({action: '123'});
}
console.log(captchaToken);
const response = await postForm(address, formId);
console.log(response);
}
function postForm(sendTo, formId) {
return new Promise(res => {
$.ajax({
type: "POST",
url: sendTo,
data: $(formId).serialize(),
contentType: "application/x-www-form-urlencoded",
dataType: "text",
success: (data) => {
return res(data);
}
});
})
}
function getCaptchaToken(opts) {
const SITE_KEY = 'SITEKEY';
return new Promise((res) => {
$.getScript('https://www.google.com/recaptcha/api.js?render=' + SITE_KEY, () => {
grecaptcha
.ready(() => {
grecaptcha
.execute(SITE_KEY, opts)
.then((token) => {
return res(token);
});
});
});
})
}
function SubmitData (data) {
// Проверка включена ли grecaptcha в настройках
if ($('#grecaptcha').length > 0) {
$.getScript('https://www.google.com/recaptcha/api.js?render=SITEKEY', function() {
grecaptcha.ready(function() {
grecaptcha.execute('SITEKEY', {action: '123'}).then(function(token) {
console.log('111');
}).then(()=> {
$.ajax({
type: "POST",
url: address,
data: $(formId).serialize(),
contentType: "application/x-www-form-urlencoded",
dataType: "text",
success: function (data) {
}
});
});
});
});
}
console.log('222');
}