To schedule an execution, you can use window.setTimeout
, to send the data to the server, you can use XMLHttpRequest
or $.ajax
.
var dados = { prop1: "Hello", prop2: "World" };
var tempo = 90 * 1000;
window.setTimeout(function () {
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST", urlParaSalvarOsDados, true);
httpRequest.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
httpRequest.addEventListener("readystatechange", function (event) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
console.log("Dados enviados com sucesso");
} else {
console.log("Erro no envio dos dados");
}
}
});
httpRequest.send(JSON.stringify(dados))
}, tempo);