25 lines
696 B
TypeScript
25 lines
696 B
TypeScript
const HTTP_BASE = "http://localhost:3000";
|
|
|
|
function httpGetAsync(theUrl, callback) {
|
|
const xmlHttp = new XMLHttpRequest();
|
|
xmlHttp.onreadystatechange = () => {
|
|
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
|
|
if (!!callback) {
|
|
callback(xmlHttp.responseText);
|
|
}
|
|
}
|
|
};
|
|
xmlHttp.open("GET", theUrl, true); // true for asynchronous
|
|
xmlHttp.send(null);
|
|
}
|
|
|
|
function sendAge(elem) {
|
|
console.log(`age: ${elem.value}`);
|
|
httpGetAsync(`${HTTP_BASE}/update/personal?age=${encodeURI(elem.value)}`, null);
|
|
}
|
|
|
|
function sendSex(elem) {
|
|
console.log("gender: " + elem.value);
|
|
httpGetAsync(`${HTTP_BASE}/update/personal?sex=${encodeURI(elem.value)}`, null);
|
|
}
|