-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (17 loc) · 775 Bytes
/
script.js
File metadata and controls
25 lines (17 loc) · 775 Bytes
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
const registrationForm = document.getElementById('registration-form');
registrationForm.addEventListener('submit', (event) => {
event.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const user = { name, email, password };
let users = JSON.parse(localStorage.getItem('users')) || [];
users.push(user);
localStorage.setItem('users', JSON.stringify(users));
//use ajax to post user data to a server
const xhr = new XMLHttpRequest();
xhr.open('POST', '/users', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(user));
window.location.href = 'data.html';
});