Answer the question
In order to leave comments, you need to log in
Why does the confirm($txt) function return the old (past) text of the file?
Hello! Here is such a problem:
Here is the code in order to return the result of the js conferr using the php function
<?php
function confirm($txt)
{
?>
<script>
let txt = "<?php echo $txt; ?>";
var confirm = confirm(txt);
$.ajax({
url: 'script.php',
type: 'POST',
data: "confirm=" + encodeURIComponent(confirm)
})
</script>
<?php
return filter_var(file_get_contents('text.txt'), FILTER_VALIDATE_BOOLEAN);
}
<?php
if (isset($_POST['confirm'])) {
$file = 'text.txt';
file_put_contents($file, $_POST['confirm']);
}
Answer the question
In order to leave comments, you need to log in
...
var confirm = confirm(txt);// здесь получаем тру или фалс, ок...
...
data: "confirm=" + encodeURIComponent(confirm) //здесь его енкодим и отправляем на сервер зачем-то...
...
return filter_var(file_get_contents('text.txt'), FILTER_VALIDATE_BOOLEAN);//читаем файл, получаем из него значение...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question