I have a reset button to delete values from a form.
I want to delete the session variable in PHP and I can not do it, it can be by jQuery.
This is the code I have:
document.getElementById("pesquisa").reset();
I have a reset button to delete values from a form.
I want to delete the session variable in PHP and I can not do it, it can be by jQuery.
This is the code I have:
document.getElementById("pesquisa").reset();
Create a function that will call the reset that you currently use and wipe the session through Ajax, just append the function on the button where the type
and Button
you pass the created function name.
PHP code:
Try {
// limpa a sessão
$_SESSION = array();
// destroy a sessão
session_destroy();
echo "sucesso";
}
cacth(Exception $e) {
echo "erro";
}
jQuery code:
function resetSession() {
$("pesquisa").reset();
$.ajax({
url: "Acao.php",
method: "POST",
data: {},
async: false,
cache: false,
success: function (data) {
if (data != "sucesso") {
Alert("Session não finalizada!");
}
else {
Alert("Session finalizada!");
}
},
error: function () {
Alert("Ocorreu uma falha!";
}
});
}