title: How to receive json from an array php in AJAX
body: <p>I'm making a AJAX call and I'm trying to receive json from an array <code>json_encode()</code>, but doesn't seem to be working. Thanks for any help.</p>
  
  <p>I'm not getting any errors and i've checked some other stackoverflow questions, but can't find a complete example. </p>
  
  <p>The problem is i'm nothing it going in to the div (#form_response) when the ajax is called and its returning everything from <code>results</code>  </p>
  
  <p>The response I get using the code below is: </p>
  
  <pre><code>{"success":true,"error":false,"complete":"&lt;div class=\"ser_mess\"&gt;success&lt;\/div&gt;","error_msg":{"empty":"&lt;div class=\"ser_mess\"&gt;empty&lt;\/div&gt;"}}
  </code></pre>
  
  <p>HTML &amp; AJAX: </p>
  
  <pre><code>&lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
  
  &lt;div class="" id="form_response"&gt;&lt;/div&gt;
  
  &lt;form id="add_property_form" action="" method="POST"&gt;
    &lt;input type="text" name="input"&gt;
    &lt;button type="submit"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;script type="text/javascript"&gt;
  $("#add_property_form").submit(function(evt){  
  
        evt.preventDefault();
        var formData = new FormData($(this)[0]);
     $.ajax({
         url: 'thescript.php',
         type: 'POST',
         data: formData,
         async: false,
         cache:false,
         contentType: false,
         processData: false,
         dataType: "json",
  
      success: function (data) {
      $('#form_response').html(data);
      }
  
    });
  return false;
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>thescript.php</p>
  
  <pre><code>header('Content-Type: application/json');
  $success = true;
  $false = false;
  
  
  
  $results = array(
     'success' =&gt; $success,
     'complete' =&gt; '&lt;div class="ser_mess"&gt;success&lt;/div&gt;',
     'error' =&gt; $false,
     'error_msg' =&gt; array('empty' =&gt; '&lt;div class="ser_mess"&gt;empty&lt;/div&gt;',)
  );
  
  if(empty($_POST['input']) ){
  
  $results['error'];
  $results['error_msg']['empty'];
  
  
  }else{
  
  $results['success'];
  $results['complete'];
  
  }
  
  
  echo json_encode($results);
  exit();
  </code></pre>