Lets say that I have an array of javascript objects, and I'm trying to transfer these objects to a php page to save them in the database. I have no problem passing a variable in php and using $ _POST ["entries"] for this variable, but I can’t figure out how to pass the entire array of objects, so I can access the values of my .entryId and .mediaType objects on the page php.
Oh, and before anyone asks, yes, so I need to do it like this because I have a flash bootloader that you guessed is loaded onto the CDN server (remote), and the remote server only responds like that js.
Thanks for any help anyone can provide.
Here are my JS features:
function test() {
entriesObj1 = new Object();
entriesObj1.entryId = "abc";
entriesObj1.mediaType = 2;
entriesObj2 = new Object();
entriesObj2.entryId = "def";
entriesObj2.mediaType = 1;
var entries = new Array();
entries[0] = entriesObj1;
entries[1] = entriesObj2;
var parameterString;
for(var i = 0; i < entries.length; i++) {
parameterString += (i > 0 ? "&" : "")
+ "test" + "="
+ encodeURI(entries[i].entryId);
}
xmlhttp.open("POST","ajax_entries.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", parameterString.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = handleServerResponseTest;
xmlhttp.send(parameterString);
}
function handleServerResponseTest() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
else {
alert("Error during AJAX call. Please try again");
}
}
}