Hi folks, long time no speak!
I'm trying to put together a simple form which I intend to use from a mobile phone. So, I'm taking a "kind of" app approach and using JSON to pass data up and down.
To aid that I'm using Knockout.js to help populate the form, validate it and serialize the data into JSON.
For those that don't know much about Knockout, I have a Javascript object (ViewModel) which represents the form data. Knockout then exposes a function
ko.toJSON(viewModel);
which, unsurprisingly, serializes the ViewModel into JSON. This is what the JSON looks like:
{"Amount":"44.55","Date":"2013-03-03","Account":"Food","StatusMessage":"New Expense"}
I then use jQuery to post that data to a PHP script on the server:
$.post("/save.php", ko.toJSON(viewModel), function(returnedData) {});
Using Chrome's Developer Tools to inspect the Network traffic, I can see the AJAX request has the JSON Form Data exactly as expected, i.e. as per the above representation.
My question is, how can my PHP script consume the Form Data? My previous experience has been posting individual fields of data which can then be accessed with
$_POST["fieldname"];
but the JSON object here doesn't have a name.
This feels like a really easy thing to achieve, and I'd expect finding a solution to be easy too but I just can't get the search terms correct.