这是我的 JavaScript 代码:
$( ".modifica_sore" ).click(function(){
var button = this;
$.ajax({
type: "POST",
url: "action/modifica_professori.php",
data: {
nome: $(button).siblings('[name="nome"]').attr("value"),
cognome: $(button).siblings('[name="cognome"]').attr("value"),
id: $(button).siblings('[name="id"]').attr("value"),
modifica_sore: $(button).siblings('[name="modifica_sore"]').attr("value"),
},
dataType: "html",
success: function(msg)
{
alert("Aggiunto con successo");
$("#risultato").html(msg);
},
error: function()
{
alert("Chiamata fallita, si prega di riprovare..."); callback in caso di fallimento
}
});
});
这是我的表格:
echo"<form method='POST'>";
echo"<fieldset>";
echo"<table>";
echo"<tr>";
echo"<td>Nome</td>";
echo"<td><input class='nome' name='nome' value='$nome'/></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Cognome</td>";
echo"<td><input class='cognome' name='cognome' value='$cognome'/></td>";
echo"</tr>";
echo"<tr>";
echo"<td></td>";
echo"<td><input type='hidden' class='id' name='id' value='$id'/></td>";
echo"</tr>";
echo"<tr>";
echo "<td> <input type='button' name='modifica_sore' class='modifica_sore' value='Modifica' /> </td>";
echo "<td> <input type='button' name='modifica_sore' class='modifica_sore' value='Elimina' /> </td>";
echo"</tr>";
echo"</table>";
echo"</fieldset>";
echo"</form>";
如果我不使用 Ajax,它可以工作,但是使用 Ajax 我有这个错误:
Notice: Undefined index: nome in C:\xampp\htdocs\xampp\action\modifica_professori.php on line 8
Notice: Undefined index: cognome in C:\xampp\htdocs\xampp\action\modifica_professori.php on line 9
Notice: Undefined index: id in C:\xampp\htdocs\xampp\action\modifica_professori.php on line 10
Notice: Undefined index: modifica_sore in C:\xampp\htdocs\xampp\action\modifica_professori.php on line 13
Notice: Undefined index: modifica_sore in C:\xampp\htdocs\xampp\action\modifica_professori.php on line 26
在 modifica_professori.php 我使用这些 $_POST var:
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$id = $_POST['id'];
$_POST['modifica_sore']
但如果它在没有 Ajax 的情况下工作,问题出在 javascript 中......:/ 谢谢你的帮助......