Create Grocy.Api.Put

This commit is contained in:
Christopher Forkner 2019-01-08 14:32:31 -07:00
parent 6b41e5212c
commit 3db750e211

View File

@ -177,6 +177,37 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
xhr.send(JSON.stringify(jsonData)); xhr.send(JSON.stringify(jsonData));
}; };
Grocy.Api.Put = function(apiFunction, jsonData, success, error)
{
var xhr = new XMLHttpRequest();
var url = U('/api/' + apiFunction);
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
{
if (success)
{
success(JSON.parse(xhr.responseText));
}
}
else
{
if (error)
{
error(xhr);
}
}
}
};
xhr.open('PUT', url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(jsonData));
};
Grocy.Api.UploadFile = function(file, group, fileName, success, error) Grocy.Api.UploadFile = function(file, group, fileName, success, error)
{ {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();