I am trying to create a javascript object so i can post it to my backend later but i am having some trouble with this.
This is my code that i am trying. When i make console.log to the object everything is fine but when i post it with $.post i got some errors. I think that error is comming because in the object i have a method and that might be causing the problem but i need that method to genereate object dynamically.
var appointmentsPart = {
"id":"appointments",
"integrationId":"1258514282"
}
var appointments = new objectPart('appointments', '1258514282');
appointments.addPart(appointmentsPart);
console.log(appointments); //this shows the correct object
function objectPart(id, integrationId){
this.id = id;
this.integrationId = integrationId;
this.part = new Array();
this.addPart = function(obj){
this.part.push(obj);
}
}
When i make console.log() everythings is shows like i want but the problem is when i want to post this object to a php file using $.post()
$.post('/api.php', {api: appointments}, function(){
console.log('test')
});
I get Cannot read property 'push' of undefined
I have created a jsfiddle to help you understand my problem.