So, guess what: I'am using AngularJs's $http
to send data to my PHP using the $_POST
method with all my data stored in an object
i will give as a parameter to $http
.
What I'am trying to achieve is to recover my ARRAY
sended trought $_POST
, in my php then properly use it in a foreach
loop.
Also I'am using $http like the following:
//Initializing my data array.
$scope.myDataArray = ['potato', 'Batman', 'Monkey'];
$scope.iHaveNoName = function(){
//action name
var actionVar = "iHaveNoName";
//Define callback function where "resp" is what my php return to me
//after sending the sql request and "parsing" it.
var callback = function(resp){
if(resp.success == 1){
//Do something in case of success
}else{
$scope.$emit('showAlert', ["An error as occured","error"]);
}
};
//Sending data trought $http using the object "way", that makes sense to me.
var params = {
'action' : actionVar,
'idBigouder' : $scope.bigouder.idUser,
//also passing the data array
'data' : $scope.myDataArray
};
//HTTP REQUEST
$http.post(url, params)
.success(callback)
.error(function(){
$scope.$emit('showAlert', ["Error","error"]);
});
};
So, my big problem is that when I try to send an array like the one I defined at the begining (myDataArray
) it seems like it didnt send nothing, I mean that when I try to recover my array in my php page using $_POST['data']
it send me an error (that's not from the else
, it means that it's my PHP who throws me an error), also i try to do a foreach
to recover the data inside my array and then use it like that: foreach ($_POST['data'] as $cell)
.
If you need more just ask, it didnt make sense for me to add the PHP as long as I've no more to show you than that, but if you want it, you are free to ask, thank you all :).
(obviously french baguette right here, be free to correct my grammar/speeling/others)