Note that there are some explanatory texts on larger screens.

plurals
  1. POSend a multi dimensional array via $.post using jquery
    text
    copied!<p>I have a global variable I'm using to store a bunch of information in a project I'm working on. It is an object with various values and I guess other objects in it. For example...</p> <pre><code>$.myVar { currentProj : "Project 1", allProjs : [], toggleVar : 0 } </code></pre> <p>Now as the program runs and I do things, I'm actually adding arrays within allProjs. I want to use the array index as the name of the project, and then it contains a bunch of information. Here is a sample of what the object looks like after running the program for a few minutes.</p> <p>(copied from Chrome's console):</p> <pre><code>$.myVar Object currentProj: "McB2" toggleVar: 0 allProjs: Array[0] McB1: Array[0] length: 0 __proto__: Array[0] McB2: Array[4] 0: "02070124" 1: "02030036" 2: "02090313" 3: "02090450" length: 4 </code></pre> <p>Now I want to pass this data to a PHP file using $.post so I can convert it to JSON and save it on the server.</p> <p>I do this basically by just running:</p> <pre><code>$.post('saveJSON.php', $.myVar, function(data) { $('#dumpspace').html(data); }); </code></pre> <p>For debugging I've got the PHP file just outputting:</p> <pre><code>print_r($_REQUEST); </code></pre> <p>Now I would expect a multi-dimensional array that I could convert to JSON and then save, but all it is spitting out is:</p> <pre><code>Array ( [currentProj] =&gt; McB2 [toggelVar] =&gt; 0 ) </code></pre> <p>So I can see that it's not sending the the allProj section of the object, but I'm not sure why! It does seem to show up when I look at the object in the console, so I'm not sure what I'm missing. </p> <p>Any help is appreciated.</p> <p>Thanks!</p> <p><b>Clarification</b></p> <p>The first section, where I declare allProjs, is it possible I'm doing something wrong there? When I run Stringify, I end up with a similarly wrong result:</p> <pre><code>JSON.stringify($.myVar) "{"currentProj":"McB2","allProjs":[],"toggleVar":0}" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload