我正在尝试使用 php 在 angularjs 中实现删除功能,如下所示:删除:index.html 视图:
<ul>
<li ng-repeat="r in result">
{{r.description}}|{{r.name}} | <a href='' ng-click = "edit(r.product_id)">edit</a> | <a href='' ng-click = "delete(r.product_id)">delete</a>
<input type="hidden" name="hdnid" ng-model="hdn" value="{{r.product_id}}"/>
</li>
</ul>
在控制器中:删除:
//delete
$scope.delete = function() {
var elem = angular.element($element);
var dt = $(elem).serialize();
//alert($element);
console.log($(elem).serialize());
$http({
method: 'POST',
url: 'php/delete.php',
data: dt,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.rs = data; // Show result from server in our <pre></pre> element
}).error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
并在 php 文件中:delete.php
<?php
include 'connect.php';
mysql_select_db($database,$con);
$id = $_POST['hdnid'];
$query = "delete from `product` where `product_id` = $id";
$result = mysql_query($query) OR die(mysql_error());
echo "You have successfully deleted ";
?>
记录被删除,但页面未刷新。在刷新页面之前,我看不到已删除的记录。我哪里错了?如何刷新页面?