So user uses a datepicker input which the value of is what is sent via ajax to the PHP which will return an array of objects containing $anoArray
below.
First Problem: ajax will only succeed using jquery; using angular $http returns "DATA WASNT AN INT"
as seen below ( this is even when setting the headers as many have posted before)... ultimately I would like to use the native angular $http service instead. WHAT I HAVE BELOW DOES RETURN DATA but leaves me with the Second Problem.
Second Problem: I wish to do various things such as sort objects and set certain key:value values as variables once the data is returned but I cannot seem to get the data returned in a format capable of this. Note* I am fairly new to programming (six months self taught) and any help is appreciated.
What should be returned:
[
{"nameF":"harry","nameL":"chicken","start":"1456790450","end":"1456790490","location":"Station 1","comments":"these are comments"},
{"nameF":"johnny","nameL":"appleseed","start":"1456790450","end":"1456790490","location":"Station 1","comments":"these are comments"}
]
My angular Controller:
app.controller('scheduleController', ['$scope', '$window', function($scope, $window) {
$scope.shifts = [];
$scope.shiftAjax = function(){
var x = $('#scheduleDate').val();
$.ajax({
method: 'post',
url: 'getSchedule.php',
data: {scheduleDate: x},
})
.done(function(response){
$scope.shifts = response;
console.log(response);
});
}
}]);
The console log shows the data as I expect it but I cannot use it as a javascript object for iteration and if change the .done to: $scope.shifts = $scope.shifts = JSON.parse(response);
then I just get a console of [object Object]
and I still cannot iterate or get key:values out of it.
PHP post url (getSchedule.php):
<?php
$startTime = strtotime($_POST['scheduleDate']);
include_once('../../classes/scheduler.php');
if(is_int($startTime)){
$var = new scheduler; //SENT TO classes/scheduler.php
$jsonArray = $var->getSchedule($startTime);
}else{
echo "DATA WASNT AN INT";
};?>