AngularJS $ http search results as a result of success, but database is not updated

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') } }); }); 
+4
source share
1 answer

I managed to find a solution based on comments, with the fact that the data is transmitted in JSON format. I had to decode the JSON format into something that PHP could use:

PHP code

 $postdata = file_get_contents("php://input"); $request = json_decode($postdata); $photoID = $request->id; 

Convert the JSON format with this PHP code, and you can use it in your SQL queries. Note that $request->id uses the same id as passed in the AngularJS $ HTTP message request.

+1
source

All Articles