title: Sending Javascript Object to PHP via Ajax
body: <p>I'm learning Ajax by failure and have hit a wall:</p>
  
  <p>I have an array (if it matters, the array is storing number id's based on what checkboxes the user checks) that is written in Javascript.</p>
  
  <p>I have a function that is called when the user clicks the 'save' button. The function is as follows:</p>
  
  <pre><code>function createAmenities() {
      if (window.XMLHttpRequest) {
          //code for IE7+, Firefox, Chrome and Opera
          xmlhttp = new XMLHttpRequest();
      }
      else {
          //code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById('message').innerHTML = xmlhttp.responseText;
          }
      }
  
      var url = "create_amenities.php";
  
      xmlhttp.open("GET", url, true);
  
      xmlhttp.send();
  
  }
  </code></pre>
  
  <p>My question is: 
  <strong>What can I put in this function to pull the array into the php script I'm trying to call ('create_amenities.php')?</strong></p>
  
  <p>furthermore, should I try using JSON? And if so, how could I send a JSON object via ajax?</p>
  
  <p>Thanks in advance.</p>