gpt4 book ai didi

Jquery传递变量到post没有表单?

转载 作者:行者123 更新时间:2023-12-01 03:41:26 25 4
gpt4 key购买 nike

在我的 super 用户页面中,我以这种方式删除和修改我的用户

<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", {
??
??

谢谢

最佳答案

使用数据参数

$.ajax({
type: "POST",
url: url,
data: {
// Your data here
},
success: success,
dataType: dataType
});

关于Jquery传递变量到post没有表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19591971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com