Finally got this working a $http POST after days of trying to find an answer. Would like to know why I have had to use two different sets of PHP code for two AngularJS $http POST requests. This are my AngularJS $http POST requests:
ContactsControllers.factory('messageFactory', ['$http', function($http){
return {
sendMessage: function(message,contactIdArray){
return $http.post('/php/sendMessage.php', {message:message,contactIdArray:contactIdArray});
}
};
}]);
ContactsControllers.factory('messagesFactory', ['$http', function($http){
return {
getContactMessages: function(contactid){
var config = {
params: {
contactid: contactid
}
};
return $http.post('/php/getMessages.php',null,config);
}
};
}]);
and my two PHP code sets:
$data = file_get_contents("php://input");
$data = json_decode($data, TRUE);
$thisMessage = $data['message'];
$contactIdArray = $data['contactIdArray'];
if($_SERVER["REQUEST_METHOD"] === "POST")
{
if(isset($_GET["contactid"]))
{
$contactid = json_decode($_GET["contactid"]);
}
else{
$result = "no contact id";
}
echo json_encode($contactid);
}
If someone could tell me why I could not just use the first sets of angularJS and PHP code for my 'messagesFactory' $http POST request, it will help me understand this a bit better. Like I said after a couple of days of trying out different code I found this http://www.angularjshub.com/examples/forms/formsubmission/ which I finally got working.
</div>