1
I am doing an exercise to change the cookie at each click through ajax. I would like to set each click a different cookie according to the content that was sent by ajax. I am sending this Ajax to exchange 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 exchange the cookie and have it presented in the next refresh. I did that which I think is pretty ugly and didn’t work. He 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;
/////////////
}
?>
And it didn’t work?
– Sr. André Baill
It didn’t work. He picks up the first cookie but not the others.
– Marcos Vinicius
As well as the first and not the others ?
– Edilson
Good afternoon, where exactly do you get the cookie? Because code node only has the part you set, you said it didn’t take the other cookies, but in your code only has a cookie the
cidade
.– Guilherme Nascimento