Error using json.stringify to send array to php
Now that I have my map function working properly, I need to send the array to php - here is my script
- <script type="text/javascript">
- $(function()
- {
- $('#submitButton').click(function(){
- var reservations = $("#main_table table input[name=name]:checked").map(function() {
- row = $(this).closest("tr");
- return {
- recordid : $(row).find('input[name=record_id]').val(),
- firstname : $(row).find('input[name=firstname]').val(),
- lastname : $(row).find('input[name=lastname]').val(),
- timeneeded : $(row).find('input[name=timeneeded]').val(),
- dateneeded : $(row).find('input[name=dateneeded]').val(),
- pickup : $(row).find('input[name=pickup]').val(),
- dropoff : $(row).find('input[name=dropoff]').val(),
- drivername : $(row).find('td:eq(7)').text()
- }
- }).get();
- console.log(reservations);
- infotosend = JSON.stringify(reservations);
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "create_assignments.php",
- data: {data : infotosend},
- dataType: 'json',
- cache: false,
- timeout: 100000,
- success: function (data) {
- console.log("SUCCESS : ", data);
- },
- error: function (e) {
- console.log("ERROR : ", e);
- }
- });
- });
- });
- </script>
- I built the .ajax part off of suggestions I found here on the forum. It's firing an error, because the php program reports ' Undefined index: infotosend' so I have something malformed, I've tried using several variations on the Data line, but I still get the same error.