-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathform.js
More file actions
23 lines (22 loc) · 1.07 KB
/
form.js
File metadata and controls
23 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 1. When someone submits a form:
jQuery("form").submit(function() {
// 2. Perform an AJAX request ($ is a shortcut for jQuery):
$.ajax({
// 3. Where to send data: use the URL from the form's action attribute
url: $("form").attr("action"),
// 4. Send the username from the input
data: { username: $("input[name=username]").val() },
// 5. What to do if data submits successfully:
success: function(result){
// 6. Change the paragraph with an id 'message' to display a welcome message
$("p#message").html("Hello there " + result.username + "! Number of checkins: " + result.checkIns);
// 7. Hide the form now the user has checked in
$("form").hide();
// 8. Once they have checked in, stop watching their position
if (typeof watchUser != "undefined")
navigator.geolocation.clearWatch(watchUser);
} // END success
}); // END ajax
// 9. Allow form to submit without reloading the page
event.preventDefault();
}) // END submit