I want to pass Javascript variable to PHP, but it is never set. I have everything in one .php file
CODE:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="asd.css">
<title>Tabulka</title>
</head>
<body>
<script>
$(document).ready(function(){
$("#table tr").click(function(){
$(this).addClass('selected').siblings().removeClass('selected');
var value = $("#table tr.selected td:first").html();
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "tabulka.php?id=" + value, true);
xmlhttp.send();
});
});
</script>
<table id="table">
<tr>
<th>A</th> <th>A</th> <th>B</th> <th>C</th> <th>D</th>
</tr>
<tr>
<td>51</td> <td>41</td> <td>1515</td> <td>419</td> <td>asd</td>
</tr>
<tr>
<td>52</td> <td>41</td> <td>1515</td> <td>419</td> <td>asd</td>
</tr>
<tr>
<td>63</td> <td>41</td> <td>1515</td> <td>419</td> <td>asd</td>
</tr>
</table>
<form method="POST">
<input type="submit" name="ok-submit" class="ok" value="OKOK">
</form>
</body>
</html>
<?php
if(isset($_REQUEST['id'])){
echo $_REQUEST['id'];
}
?>
I am using XMLHttpRequest to pass variable. It works like If I click on table row. First td is pass to php variable and print it out the print it out. But he $_REQUEST['id'] is never set.