在我的超级用户页面中删除和修改我的用户我以这种方式完成
<table>
<tr>
<td>USERID</td>
<td>NAME</td>
<td>AGE</td>
<td>DELETE</td>
<td>MODIFY</td>
</tr>
<?php
$base_url = 'this_page.php';
$query = "SELECT * FROM tbl";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$btn_del = "<input type='button' ";
$btn_del .= "onClick=\"location.href='" . $base_url . "&action=Delete&id=$row[userid]'\" ";
$btn_del .= "class='deluser' />";
$btn_mod = "<input type='button' ";
$btn_mod .= "onClick=\"location.href='" . $base_url . "&action=Modify&id=$row[userid]'\" ";
$btn_mod .= "class='moduser' />";
echo "<tr>\n";
echo "<td>" . $row['userid'] . "</td>\n";
echo "<td>" . $row['user'] . "</td>\n";
echo "<td>" . $row['age'] . "</td>\n";
echo "<td>" . $btn_del . "</td>\n";
echo "<td>" . $btn_mod . "</td>\n";
echo "</tr>";
}
</table>
<?php
switch ($_GET['action']) {
case "Delete":
// call delete method of user class
$obj->DeleteUser($_GET['idric']);
echo "<script>";
echo "document.location.href=\"$base_url\"";
echo "</script>";
break;
case "Modify":
// call modify method of user class
$obj->ModifyUser($_GET['idric']);
echo "<script>";
echo "document.location.href=\"$base_url\"";
echo "</script>";
break;
}
?>
这种方式工作得很好,但我想做一些更优雅的事情,也许使用 jquery post 和/或 ajax。
到目前为止,我一直使用 jquery 通过表单传递数据(用于验证)。
// # Form Submit
$(".Form").submit(function( event ) {
event.preventDefault();
$.post("action.admin.php", {
name: $("#name").val(),
age: $("#age").val(),
userid: $("#userid").val()
},
});
如果不使用带有 jquery post 的表单,我怎么能将我的数据传递给 action.php(在本例中为 $userid)?
// # click
$(".deluser").click(function( event ) {
event.preventDefault();
$.post("action.php", {
??
??
谢谢