Creating a guest entry, with a Matrix field, using Ajax I'm trying to submit a guest entry by building a javascript array of objects to mimic a form submission and submit using ajax. I've managed to successfully submit the entry with just a title but when trying to add Matrix/Super Table rows I'm having no luck.

I've looked here https://github.com/engram-design/SuperTable/wiki/Updating-a-Super-Table-field-from-a-front-end-form to get ideas for how this should work.

Super table block handle is answers and the Super Table field I'm trying to submit is a plain text field with the handle question.

My current code is:

$('#submitQuiz').on('click', function (e) {
  e.preventDefault();

  var testEntrySubmission = [
    {
      name: 'action',
      value: 'guestEntries/saveEntry'
    },
    {
      name: 'sectionId',
      value: '5'
    },
    {
      name: 'enabled',
      value: '1'
    },
    {
      name: 'redirect',
      value: '/'
    },
    {
      name: 'title',
      value: 'user name'
    },
    {
      name: 'answers[new1][fields][question]',
      value: 'fingers crossed'
    }
  ];

  $.post('http://mywebsite.dev/', testEntrySubmission, function(response) {
    if (response.success) {
      console.log('success')
    } else {
      // response.error will be an object containing any validation errors that occurred, indexed by field name
      // e.g. response.error.fromName =&gt; ['From Name is required']
      alert('An error occurred. Please try again.');
    }
  });
});
Answer to my question. I ended up making a form and printing out the post as JSON.

$('#submitQuiz').on('click', function (e) {
  e.preventDefault();

  var testEntrySubmission = [
    {
      name: 'action',
      value: 'guestEntries/saveEntry'
    },
    {
      name: 'sectionId',
      value: '5'
    },
    {
      name: 'enabled',
      value: '1'
    },
    {
      name: 'redirect',
      value: '/'
    },
    {
      name: 'title',
      value: 'user name'
    },
    {
    'name':'fields[answers]',
    'value':''
    },
    {
      'name':'fields[answers][new1][type]',
      'value':'6'
    },
    {
      'name':'fields[answers][new1][enabled]',
      'value':'1'
    },
    {
      'name':'fields[answers][new1][fields][question]',
      'value':'John Smith'
    },
  ];

  $.post('http://mywebsite.dev/', testEntrySubmission, function(response) {
    if (response.success) {
      console.log('success')
    } else {
      // response.error will be an object containing any validation errors that occurred, indexed by field name
      // e.g. response.error.fromName =&gt; ['From Name is required']
      alert('An error occurred. Please try again.');
    }
  });
});