I'm doing an exercise to swap the cookie on every click through ajax. I would like to set a different cookie at each click according to the content that was sent by ajax. I'm sending this Ajax to change the cookie.
<script>
jQuery(function(){
/////////////////////////////////////////
$(".cidade").on("click", function(event){
///////////////////////
event.preventDefault();
cidade = $(this).attr("id");
$.ajax({
url: "cookie.php",
data: {
cidade: cidade
}
});
});
});
</script>
I would like your help to build a simple PHP script to change the cookie and have it appear in the next refresh. I did what I think is pretty ugly and it did not work. It takes the first cookie but not the others.
<?php
if( isset($_REQUEST['cidade']) ){
///////////
ob_start();
setcookie("cidade", "", time()-3600);
$cidade = $_REQUEST['cidade'];
setcookie("cidade", $cidade);
echo $cidade;
/////////////
}
?>