Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2017 09:45
Show Gist options
  • Save anonymous/33a35fcf4edfaed88d8be94a946a07ca to your computer and use it in GitHub Desktop.
Save anonymous/33a35fcf4edfaed88d8be94a946a07ca to your computer and use it in GitHub Desktop.
$(document).ready(function() {
// create your api key in your dashboard at https://dashboard.clearbit.com/keys
var apiKey = "[REPLACE WITH YOUR API KEY]";
$("#signup").submit(function(event) {
var email = $("#email").val();
event.preventDefault();
$.ajax({
type: "GET",
url: "https://person.clearbit.com/v2/combined/find?email=" + email,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', "Bearer " + apiKey);
},
success: function(data) {
console.log(data);
$("#infos").append("<li>" + data.person.name.fullName + "</li>")
},
error: function(data) {
console.log(data);
}
})
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Fetch data from clearbit</h1>
<form action="/users" id="signup">
<input type="text" id="email">
<input type="submit">
</form>
<div class="user-infos">
<ul id="infos"></ul>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="application.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment