Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function() {
var searchQuery = window.location.search;
var ref;
var $form;
var userEmail;
if (searchQuery !== '' && searchQuery.indexOf('ref=') > -1) {
ref = searchQuery.split('=')[1];
console.log('ref',ref);
$form = $('form.newsletter-form');
if ( $form.length > 0 ) {
console.log('about to submit form');
$form.submit(function(event) {
userEmail = $form.serializeArray().find(function(o) {
return o.name === 'email';
}).value;
console.log('form was submitted', userEmail, ref);
$.ajax({
crossDomain: true,
url: 'https://lorem-ipsum-now.now.sh/api/user/' + ref,
type: 'PUT',
data: {email: userEmail},
success: function(data) {
console.log('YES', data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error", errorThrown);
}
})
});
}
console.log('there is a search query', ref, $form);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.