title: Returning two 2 json objects from PHP
body: <p>I have a small feedback form with two inputs. I want the error message to append to one another in the same div using JQuery. The error message works fine if there is only one error message, but when I return two json objects, both messages will not display at the same time. Is it possible to return 2 associative arrays with the same key to JQuery? How do I append the error messages to the same div? Everything works fine except how the error messages are displayed. </p>
  
  <p>Note: This program is a JQuery Mobile Application</p>
  
  <p>PHP code</p>
  
  <pre><code>if (isset($_POST['submit'])) {
  
      $email = $_POST['email'];
      $feedback = $_POST['feedback'];
      $errors = array();
  
      if (filter_var($email, FILTER_VALIDATE_EMAIL) &amp;&amp; !empty($email)) {
                   //Do something
      } else {
          $errors = "Invalid email.";
          echo json_encode(array("error" =&gt; "{$errors}"));
  
      }
  
      if (!empty($feedback)) {
                  //Do something
      } else {
          $errors = "Feeback field can not be empty.";
          echo json_encode(array("error" =&gt; "{$errors}"));
      }
  
      if (empty($errors)) {
          //Database Insertion here
          echo json_encode(array("success" =&gt; "Feedback submission successful."));
      }
  }  
  </code></pre>
  
  <p>JQuery Code</p>
  
  <pre><code>$(function() {
      $('#contact_form').bind('submit', function(event) {
          event.preventDefault();
          $.post('includes/form.php', $(this).serialize(), function(data) {
              if (data.error) {
  
                  $('.error').slideDown(100).html(data.error);
  
              } else {
                  $('.error').hide();
                  $('.success').slideDown(100).html(data.success);
              }
  
          }, "json");
      });
  }); 
  </code></pre>
  
  <p>HTML Form Code</p>
  
  <pre><code>         &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF'] ?&gt;" id="contact_form" data-ajax="false"&gt;
              &lt;label for="email"&gt;Email:&lt;/label&gt;
              &lt;input type="text" name="email" id="email" placeholder="Email"&gt;
  
              &lt;label for="feedback"&gt;Feedback:&lt;/label&gt;
              &lt;textarea type="text" name="feedback" id="feedback" placeholder="Feedback"&gt;&lt;/textarea&gt;              
              &lt;input type="submit" name="submit" value="Submit Feedback" class="submit"&gt;
  
          &lt;/form&gt;
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <p>Edit: I feel so silly. I forgot to append the error messages in the php script haha. Thank you to all who answered. </p>