Created
February 8, 2019 11:20
-
-
Save tomwilshere/6914efee770b03cc13953ca7baa62d02 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
// 1. When someone submits a form: | |
jQuery("form").submit(function() { | |
// 2. Perform an AJAX request ($ is a shortcut for jQuery): | |
$.post({ | |
// 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 success message | |
$("p#message").html("Form Submitted!"); | |
// 7. Hide the form now the user has submitted the form | |
$("form").hide(); | |
} // END success | |
}); // END ajax | |
// 9. Allow form to submit without reloading the page | |
event.preventDefault(); | |
}) // END submit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment