I am new to AngularJS and I am trying to execute an http service to send data to a php file for input to MySQL. I was able to get this to work using jQuery and the $.ajax function, so I'm sure my PHP is ok.
My final question is: Am I using this AngularJS service correctly? I bound ng-click to a function in an a element called routeReloader(data) . When I console.log parameters in the routeReloader function, I get the correct parameter. I also get a warning about "success." However, it does not update MySQL.
userApp.controller('photoController', ['$scope','$location','$log','$route','$http', function($scope,$location,$log,$route,$http){ $scope.routeReloader = function(parameters){ $http.post('centralcommand.php', {id: parameters}).success(function(data,status,headers,config){ alert('success'); }).error(function(data,status,headers,config){ alert('failure'); }); }; }]);
I get data in centralcommand.php file with $_POST['id'] .
JQuery Work Equivalent
$('#link-element').click(function(){ var REL = $(this).attr("rel"); var URL = 'centralcommand.php'; var dataString = 'id=' + REL; $.ajax({ type: "POST", url: URL, data: dataString, cache: false, success : function() { alert('success') } }); });
source share