title: How do I POST an array of objects with $.ajax (jQuery or Zepto)
body: <p>I'd like to POST an array of objects with $.ajax in Zepto or Jquery. Both exhibit the same odd error, but I can't find what I'm doing wrong.</p>
  
  <p>The data saves to the server when sent using a test client like 'RestEasy', and I can see the request getting mangled in the browser's net panel, so I believe JS is the culprit.</p>
  
  <p>If I send an array of objects as the data property of a POST, they are not properly sent.</p>
  
  <p>Data object:</p>
  
  <pre><code>var postData = [
      { "id":"1", "name":"bob"}
    , { "id":"2", "name":"jonas"}
    ]
  </code></pre>
  
  <p>Request:</p>
  
  <pre><code>$.ajax({
    url: _saveDeviceUrl
  , type: 'POST'
  , contentType: 'application/json'
  , dataType: 'json'
  , data: postData
  , success: _madeSave.bind(this)
  //, processData: false //Doesn't help
  });
  </code></pre>
  
  <p>Request body as seen in the browser:</p>
  
  <pre><code>"bob=undefined&amp;jonas=undefined"
  </code></pre>
  
  <p>This can be seen more directly by using the $.param method that both jQuery and Zepto use to prepare POST data.</p>
  
  <pre><code>$.param(
    [
      { "id":"1", "name":"bob"}
    , { "id":"2", "name":"jonas"}
    ]
  )
  // Output: "bob=undefined&amp;jonas=undefined"
  </code></pre>
  
  <p>So it seems like the preparation that these libraries do for complex post data is different than I expect.</p>
  
  <p>I see this answer, but I don't want to send the data as a query param as I'm POSTing lots of content.
  <a href="https://stackoverflow.com/questions/2403266/how-do-i-send-an-array-in-an-ajax-post-using-jquery">How do I send an array in an .ajax post using jQuery?</a></p>
  
  <p>What is the correct way to send multiple objects over POST using jQuery/Zepto?</p>
  
  <p>Using $.ajax({... data: JSON.stringify(postData) ...}) sends non-mangled content, but the server doesn't like the format.</p>
  
  <p><strong>Update:</strong>
  Seems like JSON.stringify sends correctly formatted content. The issue is that the server side is very, very specific about the structure of the object that it wants. If I add or remove any properties from the object, it will fail the whole process rather than using the properties that do match. This is inconvenient because it's nice to use server-sent content as a view model, but view models get changed.
  ...Still working on the best solution.</p>