title: Correctly processing and parsing JSON syntax in my AJAX post to PHP
body: <p>I am working in Codeigniter.  I have used my model in other coding.  I know it works.  </p>
  
  <p>I am getting AJAX parsererror and Failure Handler at the point of running the model.   It seems that JSON syntax is not processed correctly.  When I echo back the data for <code>$waitinglist</code> on the php end I see this in my error message in the console:</p>
  
  <p><code>"array(2) {↵  ["id_users_provider"]=&gt;↵  string(2) "86"↵  ["notes"]=&gt;↵  string(47) "emailaddress@verizon.net;9093334444@tmomail.net"↵}↵"</code></p>
  
  <p>It does not look correct.  I think it should have something like</p>
  
  <p><code>"{"appointment":{"id_users_provider":"85","notes":"emailaddress@verizon.net;9093334444@tmomail.net"}}"</code></p>
  
  <p>So where have I gone wrong?</p>
  
  <p>PHP Controller</p>
  
  <pre><code>public function ajax_register_waiting(){
     try {
          $post_data = $_POST['post_data'];
          $waitinglist = $post_data['appointment'];
  
          $this-&gt;load-&gt;model('appointments_model');
          $this-&gt;appointments_model-&gt;waitinglist_to_db($waitinglist);
  
      } catch(Exception $e) {
      echo 'Message: ' .$e-&gt;getMessage();
      }
  }
  
  public function book_waiting(){
      $this-&gt;load-&gt;view('appointments/waiting_success');//return to book view
  }
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$('#save-waitinglist').click(function(event) { 
  if(validateWaitinglistEmail() &amp;&amp; validateWaitinglistPhone()){
  
          postWaiting = new Object();
          var note = ''
  
          if($('#cell-carrier2').val() !== "" &amp;&amp; $('#phone-number2').val() !== ""){
          note = $('#email2').val()  + ";" + $('#phone-number2').val().replace(/[^\d\+]/g,"") + $('#cell-carrier2').val();
          } else {
          note = $('#email2').val();
          }
  
          postWaiting['appointment'] = {
          'id_users_provider': $('#select-provider').val(),
          'notes': note,
          };
  
          $('input[name="csrfToken"]').val(GlobalVariables.csrfToken);
          $('input[name="post_waiting"]').val(JSON.stringify(postWaiting));       
  
          var formData = jQuery.parseJSON($('input[name="post_waiting"]').val());
  
          var postData = {
              'csrfToken': GlobalVariables.csrfToken,
              'post_data': formData,
          };
  
          var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_register_waiting'; 
          $layer = $('&lt;div/&gt;');
  
          $.ajax({
              url: postUrl,
              method: 'post',
              data: postData,
              dataType: 'json',
              beforeSend: function(jqxhr, settings) {
                  $layer
                      .appendTo('body')
                      .css({
                          'background': 'white',
                          'position': 'fixed',
                          'top': '0',
                          'left': '0',
                          'height': '100vh',
                          'width': '100vw',
                          'opacity': '0.5'
                      });
              }
          })
          .done(function(response) {
              if (!GeneralFunctions.handleAjaxExceptions(response)) {
                  return false;
              }
              window.location.replace(GlobalVariables.baseUrl
                  + '/index.php/appointments/book_waiting');
          })
          .fail(function(jqxhr, textStatus, errorThrown) {
              GeneralFunctions.ajaxFailureHandler(jqxhr, textStatus, errorThrown);
          })
          .always(function() {
              $layer.remove();
          })
      }
  }); 
  </code></pre>