Saving Data From Jquery
Solution 1:
Your data is not correctly formatted for passing it to Model::save()
. Please refer to the documentation:
http://book.cakephp.org/2.0/en/models/saving-your-data.html
It should be in the following format:
Array
(
[ModelName] => Array
(
[fieldname1] => 'value'
[fieldname2] => 'value'
)
)
So the object passed to the AJAX calls data
property should look like this:
{ModelName: {fieldname1: 1, fieldname2: 2}}
In your case that would be:
{Reservation: {reservation_time_from: calEvent.start, reservation_time_to: calEvent.end, user_id: 1, laboratory_id: 1}}
Checking for a POST request instead of data
being null
might also be a good idea, ie:
if($this->request->is('post')) {
$this->Reservation->save($this->request->data);
}
Also check if you are using the Security Component which may blackhole the request.
And last but not least, check for the date format you've already mentioned, in case validation is involved this might be a problem too, at least it's a problem in case the table column expects a different format. So, format the date properly if necessary, see Convert JS date time to MySQL datetime or http://arshaw.com/fullcalendar/docs/utilities/formatDate/ in case you are using FullCalender (just guessing by your event/property names).
Solution 2:
data: {reservation_time_from : calEvent.start, reservation_time_to: calEvent.end, user_id : "1", laboratory_id : "1"},
is not valid json.
You need double quotes on your key to be considered valid.
If reservation_time_from is a variable, then you should create an object literal and add it in the following way:
myDataObject = {};
myDataObject[reservation_time_from] = calEvent.Start;
Once you have built your json object, you can then pass it in as the value for the data key.
Post a Comment for "Saving Data From Jquery"