Created
February 27, 2019 03:06
-
-
Save ryanwren/8cff51dc5b3ffd4e28b4bfa07f31599d to your computer and use it in GitHub Desktop.
This file contains 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
//getValidNumber returns a 10 digit numberwith all non-numerical characters and whitespace removed | |
var nebFormattedNumber = getValidNumber(nebUnformattedNumber); | |
if(nebFormattedNumber !== false){ | |
// format the body of the request | |
var nebPopupFormData = {}; | |
nebPopupFormData["auth_id"] = "AUTH_ID_VALUE"; | |
nebPopupFormData["auth_secret"] = "AUTH_SECRET_VALUE"; | |
nebPopupFormData["phone"] = "+1" + nebFormattedNumber; | |
nebPopupFormData["tags"] = ["website-sms-popup"]; | |
// construct a XML HTTP request | |
var nebXhr = new XMLHttpRequest(); | |
nebXhr.open('POST', "https://www.avochato.com/v1/contacts", true); | |
nebXhr.setRequestHeader('Content-Type', 'application/json'); | |
nebXhr.setRequestHeader('Host', 'www.avochato.com'); | |
// set a success callback | |
nebXhr.onreadystatechange = function () { | |
if(nebXhr.readyState === 4 && nebXhr.status === 200) { | |
console.log("Avochato contact submission successful. Response: " + nebXhr.status + " - " + nebXhr.responseText); | |
} else { | |
console.log("Avochato contact submission failed. Response: " + nebXhr.status + " - " + nebXhr.responseText); | |
} | |
}; | |
// send the collected data as JSON | |
nebXhr.send(JSON.stringify(nebPopupFormData)); | |
// print to the logs when the request is done submitting | |
nebXhr.onloadend = function () { | |
console.log("SMS number sent to Avochato"); | |
}; | |
jQuery('#mc_embed_signup').hide(); | |
jQuery('.newsletterwrapper .successful-message').show(); | |
//closeSmsModalWindow(); | |
} else { | |
jQuery('.newsletterwrapper .valid-message').show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment