-1
Guys, I have the following script:
<script>
$(document).ready(function() {
window.setInterval(function() {
$(".anuncio iframe").iframeTracker({
blurCallback: function() {
console.log("blurCallback!");
window.setTimeout(function() {
<?php setcookie("Changed","Ok", time() + 172800, $path = "/"); ?>
liberar();
}, 2000);
}
});
}, 5000);
});
</script>
The "release" function of the script comes to be executed, but for some reason the cookie is not being created. When I place the cookie right above the head ai creates, but if I leave it inside this script it does not create, as if the script skipped the creation of the cookie and went straight to execute the "release" function. Could help me understand why the cookie is not being created?
A PHP code is executed on the server only once. Putting it there in setTimeout has no effect within Javascript. If you look at the source code of the page you will see that where you put
<?php setcookie("Changed","Ok", time() + 172800, $path = "/"); ?>
is empty.– Sam
But like, is it my intention that you create just one time? I just don’t understand why the script works, calls the "release" function, but skips the cookie creation.
– Rafael_mcd
So it doesn’t make sense to put the code right there in the middle of Javascript.
– Sam
So where should I put it? Could you give me a light? I’m trying to create the cookie the moment an iframe click occurs. The iframe check works, it activates the "release" function, only the cookie that is not actually creating.
– Rafael_mcd
Communication between Javascript and PHP is done by AJAX.
– Sam