Skip to content

Instantly share code, notes, and snippets.

@captDaylight
Created August 21, 2018 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captDaylight/aa75ce98dd55cc1bf66f3cfbfa402b23 to your computer and use it in GitHub Desktop.
Save captDaylight/aa75ce98dd55cc1bf66f3cfbfa402b23 to your computer and use it in GitHub Desktop.
(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