As the title suggests I'm trying to access a nested javascript object property from within PHP.
My object is declared like so.
var requestParams = {
apiKey: appData.apiKey,
action: "addJob",
name : name,
note: note,
dropoff: dropoffAddress,
noOfCars: noOfCars,
carType: carType,
pickUpDate: pickUpDate,
pickUpTime: pickUpTime,
pickUpDateTime: {}
};
The pickUpDateTime(last property of the requestParams object) property has a nested object which I add key value pairs dynamically using a for loop.
for(var x = 0; x < dateArray.length; x++){
var dbMoment = moment(dateArray[x] + " " + pickUpTime,appData.displayDateFormat);
requestParams.pickUpDateTime[x] = dbMoment.format(appData.dbDateFormat);
}
When I log the object this is what I see in the console. So far so good.
{"apiKey":"ba6f4fc3-0f52-11e3-a51d-fefdb24fa1e7","action":"addJob","name":"Dave Manning","note":"","dropoff":"51st street","noOfCars":"1","carType":"saloon","pickUpDate":"11/06/14,13/06/14,15/06/14","pickUpTime":"14:10",******"**pickUpDateTime":{"0":"2014-06-11 14:10:00","1":"2014-06-13 14:10:00"**,**"2":"2014-06-15 14:10:00"}****,"phone":"452345657654745","pickupAddress":"popes quay","pickupLat":51.9013,"pickupLng":-8.47616,"noOfDates":3}
However, after I send it to my PHP script I can't seem to access the pickUpDateTime object. At the moment I am trying to access it using the code below. It won't work though. Moreover, when I include this line of code the function won't return anything so I can check the contents of $pickUpDateTime.
$pickUpDateTime = json_decode($this->getRequestValue("pickUpDateTime", true));
I can access every other property. So for instance this works fine.
$noOfDates = $this->getRequestValue("noOfDates", true);
I know it's probably a relatively easy fix but I can't seem to get it working.
Any help is much appreciated.
Here's what I get when I executed var_dump($_REQUEST)
responseText: " ↵Array↵(↵ [apiKey] => ba6f4fc3-0f52-11e3-a51d-fefdb24fa1e7↵ [action] => addJob↵ [name] => dave↵ [note] => ↵ [dropoff] => blarney street↵ [noOfCars] => 1↵ [carType] => saloon↵ [pickUpDate] => 11/06/14,13/06/14,15/06/14↵ [pickUpTime] => 15:43↵ [pickUpDateTime] => Array↵ (↵ [0] => 2014-06-11 15:43:00↵ [1] => 2014-06-13 15:43:00↵ [2] => 2014-06-15 15:43:00↵ )↵↵ [phone] => 5643563456435↵ [pickupAddress] => popes↵ [pickupLat] => 51.89397↵ [pickupLng] => -8.47685↵ [noOfDates] => 3↵ [_] => 1402497974065↵)↵[]"
var_dump($this->getRequestValue("pickUpDateTime", true));
what do you get? – user574632 Jun 11 at 13:33