Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS Acelle Sub
(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