Created
February 15, 2022 15:12
-
-
Save MilenFrom/8f68e5c32dbf172a0820135dd9e9a4da to your computer and use it in GitHub Desktop.
JS Acelle Sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
function validateEmail(str) { | |
var lastAtPos = str.lastIndexOf('@'); | |
var lastDotPos = str.lastIndexOf('.'); | |
return (lastAtPos < lastDotPos && lastAtPos > 0 && str.indexOf('@@') == -1 && lastDotPos > 2 && (str.length - lastDotPos) > 2); | |
} | |
$(document).ready(function(el){ | |
$(document).on('click','#ssrm-main-subscribe', function(e){ | |
e.preventDefault(); | |
var list_id = $('#ssrm-list-main-form').data('listId'); | |
var email_mk_api = $('#ssrm-list-main-form').data('api'); | |
var subscriber_email = $("input[name*='sub_email']").val(); | |
var url = 'https://api.ini.tools/acelle'; | |
var data_url = 'https://api.ini.tools/acelle?&list_uid='+list_id+'&api_token='+email_mk_api+'&EMAIL='+subscriber_email; | |
if(subscriber_email.length <= 0 || validateEmail(subscriber_email) == false){ | |
$('.acelle-error').css('display','block'); | |
$('.acelle-email-exists').css('display','none'); | |
$('.acelle-welcome').css('display','none'); | |
} else { | |
$('.acelle-error').css('display','none'); | |
// Create a request variable and assign a new XMLHttpRequest object to it. | |
var request = new XMLHttpRequest() | |
// Open a new connection, using the GET request on the URL endpoint | |
request.open('GET', data_url, true) | |
// Begin accessing JSON data here | |
request.onload = function () { | |
var data = JSON.parse(this.response) | |
if (request.status >= 200 && request.status < 400) { | |
if (typeof data.EMAIL !== 'undefined') { | |
$('.acelle-email-exists').css('display','block'); | |
$('.acelle-welcome').css('display','none'); | |
} | |
if (typeof data.status !== 'undefined') { | |
$('.acelle-email-exists').css('display','none'); | |
$('.acelle-welcome').css('display','block'); | |
} | |
} else { | |
console.log('error') | |
} | |
} | |
// Send request | |
request.send() | |
} | |
}); | |
}); | |
}(window.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment