Make separate functions for HTTP get / post.

This commit is contained in:
voussoir 2018-02-17 16:08:38 -08:00
parent 5d6c5ef2b4
commit 1b631b33e9

View file

@ -235,7 +235,7 @@ function create_message_bubble(message_area, message_positivity, message_text, l
setTimeout(function(){message_area.removeChild(message);}, lifespan); setTimeout(function(){message_area.removeChild(message);}, lifespan);
} }
function post(url, data, callback) function _request(method, url, callback)
{ {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onreadystatechange = function() request.onreadystatechange = function()
@ -253,7 +253,17 @@ function post(url, data, callback)
} }
}; };
var asynchronous = true; var asynchronous = true;
request.open("POST", url, asynchronous); request.open(method, url, asynchronous);
return request;
}
function get(url, callback)
{
request = _request("GET", url, callback);
request.send();
}
function post(url, data, callback)
{
request = _request("POST", url, callback);
request.send(data); request.send(data);
} }