23 lines
759 B
JavaScript
23 lines
759 B
JavaScript
|
// script.js
|
||
|
|
||
|
const form = document.querySelector('form');
|
||
|
const usernameInput = document.querySelector('#username');
|
||
|
const passwordInput = document.querySelector('#password');
|
||
|
|
||
|
function handleFormSubmit(event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
const username = usernameInput.value;
|
||
|
const password = passwordInput.value;
|
||
|
|
||
|
if (username === '' || password === '') {
|
||
|
alert('Please enter a valid username and password.');
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// Send an AJAX request to the server with the form data
|
||
|
const xhr = new XMLHttpRequest();
|
||
|
xhr.open('POST', 'https://example.com/login', true);
|
||
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||
|
xhr.send(`username=${username}&password=${password}`);
|
||
|
}
|