How to pass an array of javascript objects to php using POST

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");
         }
       }
    }
+5
2

. googling.

. . , POST. GET. :

Post/Get . .

var parameters="&Name[0]="+namevalue1+"&Name[1]="+namevalue2; script .

JS, ( POST GET):

    var xmlAJAXObject;

    function test() {
        xmlAJAXObject=GetxmlAJAXObject();
        if (xmlAJAXObject==null)    {
          alert ("Oops!! Browser does not support HTTP Request.");
          return  false;
        }
        var namevalue1=encodeURIComponent("Element 1");
        var namevalue2=encodeURIComponent("Element 1");

        var parameters="&Name[0]="+namevalue1+"&Name[1]="+namevalue2;

        xmlAJAXObject.open("POST", "test.php", true);   
        xmlAJAXObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlAJAXObject.setRequestHeader("Content-length", parameters.length);

        xmlAJAXObject.onreadystatechange=stateChanged;

        xmlAJAXObject.send(parameters);

    }

    function stateChanged() {

        if (xmlAJAXObject.readyState ==4)   {
            if (xmlAJAXObject.status == 200) {
                alert('Good Request is back');
                document.getElementById("show").innerHTML=xmlAJAXObject.responseText;
            }
        }
    }

    function GetxmlAJAXObject() {
        if (window.XMLHttpRequest)  {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            return new XMLHttpRequest();
        }
        if (window.ActiveXObject)  {
          // code for IE6, IE5
            return new ActiveXObject("Microsoft.Microsoft.XMLHTTP");
        }
        return null;
    }   

. . . - Google reault . , .

+3

All Articles