mirror of
https://github.com/grocy/grocy.git
synced 2025-10-10 16:00:56 +00:00
67 lines
1.0 KiB
JavaScript
67 lines
1.0 KiB
JavaScript
![]() |
var Grocy = {};
|
|||
|
|
|||
|
$(function()
|
|||
|
{
|
|||
|
var menuItem = $('.nav-sidebar').find("[data-nav-for-page='" + Grocy.ContentPage + "']");
|
|||
|
menuItem.addClass('active');
|
|||
|
});
|
|||
|
|
|||
|
Grocy.FetchJson = function(url, success, error)
|
|||
|
{
|
|||
|
var xhr = new XMLHttpRequest();
|
|||
|
|
|||
|
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('GET', url, true);
|
|||
|
xhr.send();
|
|||
|
}
|
|||
|
|
|||
|
Grocy.PostJson = function(url, jsonData, success, error)
|
|||
|
{
|
|||
|
var xhr = new XMLHttpRequest();
|
|||
|
|
|||
|
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('POST', url, true);
|
|||
|
xhr.setRequestHeader('Content-type', 'application/json');
|
|||
|
xhr.send(JSON.stringify(jsonData));
|
|||
|
}
|