-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.js
34 lines (26 loc) · 892 Bytes
/
signup.js
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
window.addEventListener("load", function () {
function sendData() {
var XHR = new XMLHttpRequest();
// Bind the FormData object and the form element
var FD = new FormData(form);
// Define what happens on successful data submission
XHR.addEventListener("load", function(event) {
alert(event.target.responseText);
});
// Define what happens in case of error
XHR.addEventListener("error", function(event) {
alert('Oups! Something goes wrong.');
});
// Set up our request
XHR.open("POST", "http://localhost:3000/users/");
// The data sent is what the user provided in the form
XHR.send(FD);
}
// Access the form element...
var form = document.getElementById("myForm");
// ...and take over its submit event.
form.addEventListener("submit", function (event) {
event.preventDefault();
sendData();
});
});