title: Passing php objects to $.post()
body: <p>I would like to pass 2 php objects as data, as they are, to $.post.</p>
  
  <pre><code>        $(function() {
              $("button").click(function() {  
                  $.post("fight.php",{player: "&lt;?php $player;?&gt;", enemy: "&lt;?php $enemy; ?&gt;"},function(result) {
                      $("#displayFight").html(result);
                  });
              });
          });
  </code></pre>
  
  <p><code>$player</code>, <code>$enemy</code> are 2 different objects with a few properties each. I would like to pass them as the whole objects they are, so that <code>fight.php</code> can deal with them.</p>
  
  <p>I've also tried <code>serialize</code>, but to no avail:</p>
  
  <pre><code>{player: $("&lt;?php $player ?&gt;").serialize()}
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>Note: With all the methods I've tried, I either get some 'unknown identifier' or $_POST comes out empty on the receiving page.</p>
  
  <p>EDIT: the json_encode part works, but the decoding fails. On the receiving page:</p>
  
  <pre><code>$player = json_decode($_POST["player"])
  </code></pre>
  
  <p>fails and returns an error: <code>json_decode() expects parameter 1 to be string, array given</code></p>