我是棱角分明的新手。我正在尝试使用角度函数更新产品。产品已成功添加。内部成功函数我正在调用其他函数。所以对它来说很好。在第二个函数里面,我试图从数据库中获取记录。但它没有发生。服务器端脚本语言是PHP。以下是我的编码:
var listApp = angular.module('listApp', []);
listApp.controller('PhoneListCtrl', function($scope, $http){
$scope.title= 'I am Excited';
$scope.product_submit = function() {
$http.post('db.php?action=add_product',
{
'prod_name' : $scope.prod_name,
'prod_desc' : $scope.prod_desc,
'prod_price' : $scope.prod_price,
'prod_quantity' : $scope.prod_quantity
}
)
.success(function (data, status, headers, config) {
alert("Product has been Submitted Successfully");
$scope.get_product();
})
.error(function(data, status, headers, config){
alert("Unable to update");
});
}
$scope.get_product = function() {
console.log('Block 1');
$http.get("db.php?action=get_products").success(function(data)
{
console.log(data);
//$scope.product_detail = data;
//$scope.pagedItems = data;
});
}
});
在上面的方法里面成功方法我正在调用get_product()。在第二种方法中我添加了console.log('Success')。因此它工作正常。之后它没有向服务器发送任何请求?请指教。
感谢:http://tech-blog.maddyzone.com/javascript/perform-addeditdeleteview-php-using-angular-js
答案 0 :(得分:0)
$scope.get_product = function() {
console.log('Block 1');
$http.get("db.php?action=get_products").success(function(data)
{
console.log(data);
//$scope.product_detail = data;
//$scope.pagedItems = data;
});
}
$scope.product_submit = function() {
$http.post('db.php?action=add_product',
{
'prod_name' : $scope.prod_name,
'prod_desc' : $scope.prod_desc,
'prod_price' : $scope.prod_price,
'prod_quantity' : $scope.prod_quantity
}
)
.success(function (data, status, headers, config) {
alert("Product has been Submitted Successfully");
$scope.get_product();
})
.error(function(data, status, headers, config){
alert("Unable to update");
});
}