I'm fairly new to AngularJS, and I'm trying to perform an http service to send data to a php file for input into MySQL. I have been able to get this to work using jQuery and the $.ajax function so I am sure my PHP is alright.
My ultimate question: Is the way that I am implementing this AngularJS service correct? I have binded an ng-click to a function on an a element called routeReloader(data). When I console.log the parameters within the routeReloader function, I get the correct parameter. I am also getting an alert box of "success." However, it isn't updating 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 the data in the centralcommand.php file using $_POST['id'].
JQuery Working 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')
}
});
});