Pass javascript var to php using ajax on same page
My php/html code below'
After one of the <li> tags is chosen the var choice contains the text() value of that <li>.
How can I/is it possible to use AJAX to pass choice to the php code
- <?php
set_include_path( '../../include' );
error_reporting (E_ALL ^ E_NOTICE);
$str=<<<LABEL
<style>
.hov:hover {
color: red;
font-weight: bold;
}
li {
list-style-type:none;
}
</style>
<script src="../jquery/jquery-2.1.4.js"></script>
<script type="text/javascript">
$(function(){
$("li.hov").click(function () {
var choice="";
console.log("testing");
choice=($( this ).text());
alert("You chose: " + choice);
- ADD AJAX CODE HERE ? TO PASS choice TO PHP CODE ON THIS PAGE ?
});
});
</script>
LABEL;
chdir('/home/rick/Desktop');
echo $str;
$path=getcwd();
$items=scandir($path);
echo "<p>Contents of $path</p>";
echo '<ul>';
$i=0;
foreach($items as $item) {
if(is_file($item) || $item=="." || $item=="..") {
continue;
}
$disp='disp'.++$i;
echo "<li id=$disp class='hov' >$item</>";
}
echo '</ul>';
DO STUFF HERE WITH RESULT PASSED BACK BY AJAX ?
?>