Skip to content

Instantly share code, notes, and snippets.

@dangerouse
Last active August 8, 2016 22:50
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 dangerouse/e0d64500c370a8865ea8ddf81be238b9 to your computer and use it in GitHub Desktop.
Save dangerouse/e0d64500c370a8865ea8ddf81be238b9 to your computer and use it in GitHub Desktop.
CloudSponge Widget Reference - Post selected contacts to your server
<!DOCTYPE html>
<html>
<head>
<!--
Include the script anywhere on your page, usually in the head
(don't forget to replace `localhost-only` with your own CloudSponge Widget Key)
-->
<script src="//api.cloudsponge.com/widget/localhost-only.js"></script>
<script>
// extra widget options go here:
cloudsponge.init({
afterSubmitContacts: function(contacts, source, owner) {
var url = "/path/to/your/contacts/endpoint",
http = new XMLHttpRequest(),
payload = {contacts: contacts, source: source, owner: owner};
// crate the http connection
http.open("POST", url, true);
// Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/json");
http.onreadystatechange = function() {// Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(JSON.stringify(payload));
}
});
</script>
</head>
<body>
<a class="cloudsponge-launch">Add from Address Book</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment