I need to, for example, send mail if in this window, a user pressed OK. Can I do it without Ajax?
var runPHP = confirm("Run PHP script?");
alert( runPHP );
I need to, for example, send mail if in this window, a user pressed OK. Can I do it without Ajax?
var runPHP = confirm("Run PHP script?");
alert( runPHP );
One way to do this without using AJAX would be to create a cookie with JavaScript then use JavaScript again to refresh the page and finally just let PHP use the cookie data that was set earlier to decide whether to run the function or not like this:
var runPHP = confirm("Run PHP script?");
if(runPHP){
document.cookie = "runPHP=yes";
window.location.reload();
} else {
document.cookie = "runPHP=no";
window.location.reload();
}
<?php
if(isset($_COOKIE["runPHP"])) {
if(strpos($_COOKIE["runPHP"],"yes")>=0){
somePHPFunction();
}
}
?>
Logic via - How do I edit PHP variable with JavaScript/jQuery?