Last active
February 7, 2021 20:48
-
-
Save LouisdeBruijn/8ed78ae7c9a074a2ffab9d9ecee244b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| document.body.addEventListener( 'click', function (event) { | |
| if( event.target.className === 'unique_class_name' ) { | |
| const form = event.target.form; | |
| const data = new FormData(form); | |
| const request = new XMLHttpRequest(); | |
| request.open(form.method, form.action, true); | |
| request.send(data); | |
| // logFormData(data); | |
| request.addEventListener("load", function () { | |
| if (this.readyState === 4 && this.status === 200) { | |
| // catch JsonResponse from Django | |
| const response = JSON.parse(this.responseText); | |
| // display message | |
| const messages = document.getElementById("messages-list"); | |
| messages.innerHTML += response.msg; | |
| fade_alerts(); | |
| } | |
| }); | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment