title: Passing JSON object to PHP script
body: <p>I am trying to pass a JSON object that looks similar to this:</p>
  
  <pre><code> {"service": "AAS1", "sizeTypes":[{"id":"20HU", "value":"1.0"},{"id":"40FB","2.5"}]}
  </code></pre>
  
  <p>Just a note: In the sizeTypes, there are a total of about 58 items in the array.</p>
  
  <p>When the user clicks the submit button, I need to be able to send the object to a PHP script to run an UPDATE query.  Here is the javascript that should be sending the JSON to the PHP script:</p>
  
  <pre><code> $('#addNewSubmit').click(function()
   {
     var payload = {
       name: $('#addservice').val();
       sizeTypes: []
     };
  
     $('input.size_types[type=text]').each(function(){
       payload.sizeTypes.push({
         id: $(this).attr('id'),
         value: $(this).val()
        });
     });
  
     $.ajax({
       type: 'POST',
       url: 'api/editService.php',
       data: {service: payload},
       dataType: 'json',
       success: function(msh){
         console.log('success');
       },
       error: function(msg){
         console.log('fail');
       }
     });
   });
  </code></pre>
  
  <p>Using the above click function, I am trying to send the object over to php script below, which is in api/editService.php:</p>
  
  <pre><code> &lt;?php
   if(isset($_POST['service']))
   {
     $json = json_decode($_POST['service'], true);
  
     echo $json["service"]["name"] . "&lt;br /&gt;";
  
     foreach ($json["service"]["sizeTypes"] as $key =&gt; $value){
       echo $value["value"] . "&lt;br /&gt;";
     }
   }
   else
   {
     echo "Nooooooob";
   }
   ?&gt;
  </code></pre>
  
  <p>I do not have the UPDATE query in place yet because I am not even sure if I am passing the JSON correctly.  In the javascript click function, you see the SUCCESS and ERROR functions.  All I am producing is the ERROR function in Chrome's console.</p>
  
  <p>I am not sure where the error lies, in the JavaScript or the PHP.</p>
  
  <p>Why can I only produce the error function in the AJAX post?</p>
  
  <h2>Edit</h2>
  
  <p>I removed the dataType in the ajax call, and added JSON.stringify to data:</p>
  
  <pre><code> $.ajax({
     type: 'POST',
     url: 'api/editService.php',
     data: {servce: JSON.stringify(payload)},
     success: function(msg){
       console.log('success');
     },
     error: function(msg){
       console.log('fail'), msg);
     }
   });
  </code></pre>
  
  <p>In the PHP script, I tried this:</p>
  
  <pre><code> if(isset($_POST['service'))
   {
     $json = json_decode($_POST['service'], true);
  
     foreach ($json["service"]["sizeTypes"] as $key =&gt; $value){
       $insert = mysqli_query($dbc, "INSERT INTO table (COLUMN, COLUMN, COLUMN) VALUES (".$json["service"] . ", " . "$value["id"] . ", " . $value["value"]")");
     }
   }
   else
   {
     echo "noooooob";
   }
  </code></pre>
  
  <p>With this update, I am able to get the success message to fire, but that's pretty much it.  I cannot get the query to run.</p>