I am using the SLIM 3.9 framework as an API and as a client a web page in javascript. I have the following problem, when I insert new information from the client side to the database, the record is created correctly at the mysql level, but when I try to consult it at the javascript level, it does not return the last inserted record, it seems that the browser caches the GET request. I have tried to pass in the NO-CACHE header but without success. Does anyone know what could be going on? By the way, if I change the method to POST I have no problem, but with GET it seems that a type of cache is created. Can anyone help me. Thanks
My Javascript method:
getLastRegister(){
var myHeaders = new Headers();
myHeaders.append('pragma', 'no-cache');
myHeaders.append('cache-control', 'no-cache');
return new Promise((resolve, reject) => {
let self = this;
let month = ""
let year = ""
fetch('/xxxxxx/api/xxxxxxx/getLastRegister', {
method: 'GET',
headers: myHeaders
})
.then(response => response.json())
.then(data => {
if(data.success){
data.data.forEach((e)=>{
console.log(e);
month = e.month;
year = e.Year;
});
resolve({year:year, month:month})
}
else{
self.alertError.customMsg.innerHTML = 'A error was ocurred: '+data.message;
self.alertError.show();
console.error('Error:', data.message);
reject(data.message);
}
})
.catch((error) => {
self.alertError.customMsg.innerHTML = error;
self.alertError.show();
console.error('Error:', error);
reject(error);
});
});
}