Tramite la funzione ajax di Jquery vorrei passare un valore ad un file php
file php
Codice PHP:
<?php
$id = $_POST['id'];
if ($id==1) echo 'Chiamata numero 1';
if ($id==2) echo 'Chiamata numero 2';
if ($id==3) echo 'Chiamata numero 3';
if ($id!=1 && $id!=2 && $id!=3) echo $id;
?>
file js
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File corso</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('span.delete').click(function()
{
var id = jQuery(this).attr('id')
$.ajax({
type: 'POST',
url: 'test.php',
data: id,
success: function(response){
jQuery('<div></div>').addClass('output').insertAfter('table.file');
jQuery('.output').html(response);
}
});
alert (id);
});
});
</script>
</head>
<body>
<?php require_once 'Cartella.php' ?>
<?php
if (count($conenuto)>0)
{
?>
<table class="file">
<tr>
<th>NOME FILES</th>
<th>DIMENSIONI</th>
<th>AZIONI</th>
</tr>
<tr>
<?php
foreach($conenuto as $valore)
{
echo '<td><a href=\''.$percorso_corso.'/'.$valore.'\'>'.$valore.'</a></td>
<td>-</td>';
echo '<td><span class="delete" id="'.$percorso_corso.'/'.$valore.'">X</span></td>
</tr>';
}
}
else
echo '<h1>La cartella [i]'.substr($percorso_corso, $car_dir_prin).' [/i]è vuota</h1>';
?>
</tr></table>
</body>
</html>
Il valore che li vorrei passare è id dello span, ma non va mi dice
Notice: Undefined index: id in.....