A
A
Anton2021-07-02 21:51:58
PHP
Anton, 2021-07-02 21:51:58

How to pass value to php variable with such request?

Greetings, please tell me how to pass a value from javascript to a php variable with such an asynchronous request.

html:

<td id="varvalue">TestValue</td>
<script>
var sendvar = document.getElementById("varvalue").innerHTML;
async function upIncome(){
    let response = await fetch('test.php',{
        method: 'POST'
    });
    document.querySelector('.from-server').innerHTML = await response.text();
}
 
document.querySelectorAll("input[type='checkbox']").forEach(item=>{
item.addEventListener('click', upIncome)
});
</script>

test.php:
<?
$hex = ????; //значение innerhtml <td id="varvalue">
echo $hex;
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Volkov, 2021-07-03
@AronTito

There are several solutions here, but read more on stackoverflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question