Site-Proximo/assets/js/ajaxManager.js
2020-02-11 15:12:31 +01:00

57 lines
1.4 KiB
JavaScript

class AjaxManager {
static async get(type) {
let data = {
type: type,
action: 'get',
};
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['data'];
}
static async delete(id, type) {
let data = {
type: type,
action: 'remove',
data: id,
};
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['status'];
}
static async save(data, isNew, type) {
let formattedData = {
type: type,
action: isNew ? 'create' : 'update',
data: data,
};
console.log(formattedData);
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(formattedData),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['data'];
}
}