Note that there are some explanatory texts on larger screens.

plurals
  1. POpass an array from jQuery to PHP (and actually go to the page after submit)
    primarykey
    data
    text
    <p>This seems like it would have been simple, but what i was doing was creating an array in jQuery and sending it to a php via ajax and inserting the records into a db. But what i want to do now is create the array exactly the same but instead of ajax, i'd like to go to the php page and view what it has received.</p> <p>How would i go about doing this?</p> <p>I'm using this jQuery:</p> <pre><code>$('#preview').live('click',function(){ var postData = {}; $('#items tr').not(':first').each(function(index, value) { var keyPrefix = 'data[' + index + ']'; postData[keyPrefix + '[index]'] = index; postData[keyPrefix + '[supp_short_code]'] = $(this).closest('tr').find('.supp_short_code').text(); postData[keyPrefix + '[project_ref]'] = $(this).closest('tr').find('.project_ref').text(); postData[keyPrefix + '[om_part_no]'] = $(this).closest('tr').find('.om_part_no').text(); postData[keyPrefix + '[description]'] = $(this).closest('tr').find('.description').text(); postData[keyPrefix + '[quantity_input]'] = $(this).closest('tr').find('.quantity_input').val(); postData[keyPrefix + '[cost_of_items]'] = $(this).closest('tr').find('.cost_of_items').text(); postData[keyPrefix + '[cost_total_td]'] = $(this).closest('tr').find('.cost_total_td').text(); }); $.ajax ({ type: "POST", url: "preview.php", dataType: "json", data: postData, cache: false, success: function() { } }); }); </code></pre> <p>And this PHP:</p> <pre><code>if (isset($_POST['data']) &amp;&amp; is_array($_POST['data'])) { foreach ($_POST['data'] as $row =&gt; $data) { echo $data['index']; echo $data['project_ref']; echo $data['supp_short_code']; echo $data['om_part_no']; echo $data['description']; echo $data['quantity_input']; echo $data['cost_of_items']; echo $data['cost_total_td']; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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