我希望通过 AngularJS 和 PHP 在 MySQL 数据库中添加一条记录。记录添加成功但没有看到AngularJS效果。即页面不会自动刷新。下面是给出的代码:
控制器:
$scope.add = function() {
var elem = angular.element($element);
var dt = $(elem).serialize();
//alert($element);
console.log($(elem).serialize());
$http({
method: 'POST',
url: 'php/add.php',
data: dt,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status) {
$scope.status = status;
$scope.data = data;
console.log(data);
data.push(this);
$scope.products = data; // Show result from server in our <pre></pre> element
}).error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
索引.html
<li ng-repeat="product in products" ng-model = 'products'>
{{product.description}}|{{product.name}} | <a href='edit.html' ng-click = "edit(product.product_id)">edit</a> | <a href='' ng-click = "del(product.product_id)" ng-hide="isHidden">delete</a>
<input type="hidden" name="hdnid" ng-model="hdn" value="{{product.product_id}}"/>
</li>
添加.php
<?php
include 'connect.php';
mysql_select_db($database,$con);
$nm = $_POST['keywords'];
$desc = $_POST['desc'];
$query = "INSERT INTO `product`(`name`,`description`) VALUES ('$nm', '$desc')";
$result = mysql_query($query) OR die(mysql_error());
?>
我应该怎么做才能自动刷新页面?