Embezzle/client/index.js

30 lines
931 B
JavaScript
Raw Normal View History

2020-02-15 23:22:09 +00:00
url="http://127.0.0.1:3000"
function send() {
data = {name: $('#name').val(), ownerID: $("#ownerID").val(), gameID: $("#gameID").val(), seats: $("#seats").val()}
console.log(JSON.stringify(data))
let xhr = new XMLHttpRequest();
xhr.open("POST", url + "/" + $('#location').val(), true)
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(JSON.parse(xhr.responseText))
}
}
xhr.send(JSON.stringify(data))
}
function get() {
let xhr = new XMLHttpRequest();
xhr.open("GET", url + "/" + $('#location').val(), true)
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(JSON.parse(xhr.responseText))
}
}
xhr.send()
}