//--------------------------------------------------------------------------
// ## ESTA FUNCION ES IGUAL A load() de Jquery |
// ## IGUAL QUE Jquery LA CARGA EN UN DIV |
/* |
|
para llamarla ==> Carga('url',divID); |
|
*/// |
//-------------------------------------------------------------------------|
function Carga(pag, divID) {
fetch(pag).then(response => response.text()).then(response => {
divID.innerHTML = response;
})
}
//##########################################################################
//--------------------------------------------------------------------------
// ## ESTA FUNCION ME LEE LOS TD DE UNA TABLA EN EL DOM Y |
// ## ME DEVUELVE EL VALOR SEGUN SU ID |
/* |
|
para llamarla ==> valornode(este,'elID'); |
|
*/// |
//-------------------------------------------------------------------------|
function valornode(este, elID) {
var dev;
var nodelist = este.parentNode.parentNode.childNodes;
for (var i = 0; i < nodelist.length; i++) {
var nodeItem = nodelist.item(i);
if (nodeItem.nodeName == "TD" && nodeItem.id == elID) {
dev = nodeItem.innerHTML;
}
}
return dev;
}
//###########################################################################
//-------------------------------------------------------------------------------|
// ### ENVIO UN FORMULARIO Y DEVUELVE LA RESPUESTA ### // |
/* |
para llamarla ==> FrmJson('carpeta/archvo.php',formID).then((retorna) => { |
console.log(retorna); |
}) |
*/// |
//-------------------------------------------------------------------------------|
async function FrmJson(pag, frm) {
const opciones = {
method: 'POST',
body: new FormData(frm)
};
try {
const fetchResp = await fetch(pag, opciones);
const retorna = await fetchResp.text();
return retorna;
} catch (e) {
return e;
}
}
//################################################################################
//---------------------------------------------------------------------------------------------------------------|
// ### ENVIO UN JSON Y DEVUELVE LA RESPUESTA ### // |
/* |
para llamarla ==> QryFecth('carpeta/archvo.php',{'valor1': 'uno','valor2': 'dos'}).then((retorna) => { |
console.log(retorna); |
}) |
*/// |
//---------------------------------------------------------------------------------------------------------------|
async function QryFecth(pag, dataJson) {
var i = -1; var jsdata = new FormData();
Object.keys(dataJson).forEach(e => {
i++; jsdata.append(Object.keys(dataJson)[i], dataJson[e])
});
const opciones = {
method: 'POST',
body: jsdata
};
try {
const fetchResp = await fetch(pag, opciones);
const retorna = await fetchResp.text();
return retorna;
} catch (e) {
return e;
}
}
//################################################################################################################
//--------------------------------------------------------------------------------------------------------|
// ### ENVIO UN JSON Y LA RESPUESTA LA PINTO EN UN DIV ### // |
/* |
|
para llamarla ==> QryFecthDiv('carpeta/archvo.php',{'valor1': 'uno','valor2': 'dos'},'divID') |
|
*/// |
//--------------------------------------------------------------------------------------------------------|
function QryFecthDiv(pag, dataJson, div) {
var i = -1; var jsdata = new FormData();
Object.keys(dataJson).forEach(e => {
i++; jsdata.append(Object.keys(dataJson)[i], dataJson[e])
});
fetch(pag, {
method: "POST",
body: jsdata
})
.then(response => response.text()).then(response => {
div.innerHTML = response;
})
}
//########################################################################################################