你们能帮助我找出我的ajax呼叫失败的地方吗?它确实调用了正确的PHP脚本,但它无法根据用户ID删除用户。我把我的代码放在下面。
cms / users HTML
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="../cms/events">Manage Events</a></li>
<li><a href="#">Manage Speakers</a></li>
<li><a href="#">Manage Surveys</a></li>
<li><a href="#">Manage Contact Lists</a></li>
<li><a href="../users">Manage Users</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Hassan Said <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="../manage/1">Manage Account</a></li>
<li><a href="../users">Manage Users</a></li>
<li><a href="../logout">Logout</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
</div>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h2 class="form-signin-heading">CMS Users</h2>
<span class="alert alert-success form-control" id="delete_succuessful"></span>
<span class="alert alert-danger form-control" id="delete_unsuccessful"></span>
<table class="table table-hover">
<thead>
<th>Username</th>
<th>Last Name</th>
<th>First Name</th>
<th>Delete</th>
<th>Edit</th>
<th>View</th>
<th>User Active?</th>
</thead>
<tbody>
<tr><td>imaqsood</td><td>Maqsood</td><td>Irum</td> <td><a data-toggle="modal" data-target="#deleteConfirm" data-first_name="Irum" data-last_name=" Maqsood " data-user_id=" 2 " class="confirmDelete"><span class="glyphicon glyphicon-remove"></span></a></td>
<td><a href="../cms/edituser/2"><span class="glyphicon glyphicon-pencil"></span></a></td>
<td><a href="../cms/viewuser/2"><span class="glyphicon glyphicon-search"></span></a></td>
<td><span class="glyphicon glyphicon-ok"></span></td>
</tr><tr><td>hsaid</td><td>Said</td><td>Hassan</td> <td><a data-toggle="modal" data-target="#deleteConfirm" data-first_name="Hassan" data-last_name=" Said " data-user_id=" 2 " class="confirmDelete"><span class="glyphicon glyphicon-remove"></span></a></td>
<td><a href="../cms/edituser/1"><span class="glyphicon glyphicon-pencil"></span></a></td>
<td><a href="../cms/viewuser/1"><span class="glyphicon glyphicon-search"></span></a></td>
<td><span class="glyphicon glyphicon-ok"></span></td>
</tr><tr><td>t</td><td>T</td><td>T</td> <td><a data-toggle="modal" data-target="#deleteConfirm" data-first_name="t" data-last_name=" t " data-user_id=" 2 " class="confirmDelete"><span class="glyphicon glyphicon-remove"></span></a></td>
<td><a href="../cms/edituser/18"><span class="glyphicon glyphicon-pencil"></span></a></td>
<td><a href="../cms/viewuser/18"><span class="glyphicon glyphicon-search"></span></a></td>
<td><span class="glyphicon glyphicon-ok"></span></td>
</tr> </tbody>
</table>
<a href="../cms/edituser"><button type="button" class="btn btn-primary btn-lg btn-block">Add A New User</button></a>
</div>
<div class="modal fade" id="deleteConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Delete Confirmation</h4>
</div>
<div class="modal-body">
<input type="hidden" id="currDeleteId">
<p>Are you sure you want to delete: <em><span class="last_name" id="last_name"></span>, <span class="first_name" id="first_name"></span></em></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="delete-confirmation">Yes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal --></div>
cms / users JQuery
<script>
$(document).on("click", ".confirmDelete", function () {
var userDeleteFirstName = $(this).data('first_name');
var userDeleteLastName = $(this).data('last_name');
var userDeleteUserId = $(this).data('user_id');
$(".first_name").text( userDeleteFirstName );
$(".last_name").text( userDeleteLastName.trim() );
$("#currDeleteId").val( userDeleteUserId.trim() );
});
$(document).on("click", "#delete-confirmation", function(){
var id_to_delete = $('#currDeleteId').val();
$.ajax({
url: "../cms/delete/" + id_to_delete,
type: "POST",
success: function(){
$("#delete_succuessful").text("User " + userDeleteLastName + ", " + userDeleteFirstName + " was deleted.");
},
error: function(){
$("#delete_unsuccuessful").text("User " + userDeleteLastName + ", " + userDeleteFirstName + " was not deleted.");
}
});
});
</script>
/ cmscontroller / delete PHP Script
public function deleteUser($id){
if(!isset($_SESSION['cms_user_session'])){
header('location:.login');
}else{
echo $id;
$query = $this->Cms->where('cms_user_id','=',$_SESSION['cms_user_session']);
$query = $this->Cms->find();
$first_name = ucwords($query[0]['first_name']);
$last_name = ucwords($query[0]['last_name']);
$this->set('title', strtoupper('cms').ucwords(' deleting user'));
$query = $this->Cms->delete(array('cms_user_id',$id));
}
}
我认为问题可能在于ajax调用,因为它确实将数据发送到/ cms / delete / id,这是由firefox的inspect元素确认的。但是ajax成功调用什么也没做。请让我知道任何想法