-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_example_html.html
61 lines (52 loc) · 1.55 KB
/
ajax_example_html.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/site.css">
</head>
<body>
<nav></nav>
<main class="container">
<div class="col-md-6">
<h2>Creep on some code!</h2>
<form action="">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="enter a user's github address">
<button type="submit">Lookup!</button>
</form>
</div>
<div class="col-md-6">
<h3></h3>
</div>
</main>
<footer></footer>
<script src="js/jquery-3.0.0.js"></script>
<script src="js/bootstrap.js"></script>
<script>
function addEmailToPage(profile) {
$('h3').html("The users email address is " + profile.email);
}
function getGitHubProfile(username) {
var request = $.get("https://api.github.com/users/" + username);
request.fail(function(error) {
console.log(error);
});
request.done(function (response) {
console.log(response);
profile = response;
// then add their email address to the page
addEmailToPage(profile);
});
}
// when the user types in a username and hits submit
$('button').click(function(e) {
e.preventDefault();
var username = $("#username").val();
// call the getGitHubProfile() function with their username
getGitHubProfile(username);
});
</script>
</body>
</html>