Created
August 21, 2018 22:32
-
-
Save captDaylight/aa75ce98dd55cc1bf66f3cfbfa402b23 to your computer and use it in GitHub Desktop.
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() { | |
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