我的 jquery ajax 调用正在更新我的数据库,但它没有更新页面。我不清楚成功参数请帮忙
jQuery:
<script type="text/javascript">
function changeStatus(userStatus,userId) {
var getParameters = "userStatus = " + userStatus + "&userId = " + userId;
$.ajax({
type: 'GET',
url: 'blogUsers.php',
data: getParameters,
success: function() {
}
});
}
</script>
php:
<?php
if( isset( $_GET['userId'] ) && isset( $_GET['userStatus'] ) ) {
$userId = $_GET['userId'];
$userStatus = $_GET['userStatus'];
switch( $userStatus ) {
case "1":
$changeStatus=0;
break;
case "0":
$changeStatus=1;
break;
default:
$changeStatus="";
}
$Query = "UPDATE blog_users SET blog_user_status='$changeStatus' WHERE blog_user_id='$userId'";
$Result = mysql_query( $Query );
}
?>
这是用户网格在页面上的显示方式:
function viewUsers() {
$Query="SELECT * FROM blog_users";
$Result=mysql_query($Query);
while ($row=mysql_fetch_array($Result)) {
$userId=$row['blog_user_id'];
$userName=$row['blog_user_name'];
$userEmail=$row['blog_user_email'];
$userStatus=$row['blog_user_status'];
?>
<tr><td><?php echo $userId; ?></td>
<td><?php echo $userName; ?></td>
<td><?php echo $userEmail; ?></td>
<td><?php if($userStatus==1){echo "Active";}else echo "Banned"; ?></td>
<?php
$action="";
switch($userStatus){
case "1":
$action="Ban User";
break;
case "0":
$action="Activate User";
break;
default:
$action="";
}
?>
<td><a href="#" onclick="changeStatus(<?php echo $userStatus; ?>,<?php echo $userId; ?>);"><?php echo $action; ?></a></td>
<?php } } ?>
这就是我调用函数的方式”
<td><a href="#" onclick="changeStatus(<?php echo $userStatus; ?>,<?php echo $userId; ?>);"><?php echo $action; ?></a></td>
thsi 是需要更新的部分:
<table class="tablesorter" cellspacing="0">
<thead>
<tr>
<th class="header">userId</th>
<th class="header">userName</th>
<th class="header">userEmail</th>
<th class="header">userStatus</th>
<th class="header">Actions</th>
</tr>
</thead>
<tbody>
<?php viewUsers(); ?>
</tbody>
</table>
实际上,$action
变量应该在点击时更改为激活用户或 Bann 用户!