Saving array of objects with jQuery AJAX and PHP?
Hi I'm using fullcalendar, jQuery and CakePHP. When using the clientEvents function I get all of the calendar events in an array of objects. I then pass that array to an action via jQuery's $.ajax of type post. But when I inspect the post data I get something like:
Array
(
[undefined] =开发者_JAVA百科> undefined
)
What seems to be the problem?
Thanks in advance!
This probably means you're not building the array in Javascript correctly. Something like
values = myValues(); // getting values
var data = { };
data[values.variableThatDoesNotExist] = values.anotherVariableThatDoesNotExist;
The two non-existing variables are of type undefined
, which gets cast to the string "undefined", and that's what the key and value in the object will be called.
Try debugging your Javascript.
$.post("/url/to/post/to",
{ post_param1: value1, post_param2: value2 }
function(response) {
}
});
Should work great...
精彩评论