title: Json object returned from PHP with json_encode() , but then invalid json object in my javascript
body: <p>I echo a simple associative array read from a mySQL table back to my jquery b.m.o the json_encode($array) method. However, my .ajax call fails back in the jquery and it seems due to the object not being a valid json object. I did some debugging in chrome and under the network tab verified the response preview- does indeed look to be in perfect json format:</p>
  
  <p>{"UserName":"DehanL","UserPassword":"admin","UserEmail":"dehan@rocketmail.com"}</p>
  
  <p>Here is my php:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
  
  
  
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbName ="dbPodiumPro";
  
  $inUsername = $_POST["name"];
  $inPassword = $_POST["password"];
  
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbName);
  
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  //Use the dbPodiumPro
  mysqli_select_db($conn,"dbPodiumPro");
  
  
  $sql = "SELECT * FROM users WHERE UserName='$inUsername' AND UserPassword ='$inPassword' ";
  
  $result = mysqli_query($conn,$sql);
  
  // Fetch one row
  $row=mysqli_fetch_assoc($result);
  
  //Check to see if the username and password combo exists
  if(!empty($row['UserName']) AND !empty($row['UserPassword'])) 
      { 
  
      //$_SESSION['UserName'] = $row['UserPassword']; 
      //echo $_SESSION; 
  
      echo json_encode($row);
  
      } 
  
  else { echo "Be gone imposter!"; }
  
  
  $conn-&gt;close();
  
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then the jquery:</p>
  
  <pre><code>$.ajax({
          type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
          url: 'php/loginrequest.php', // the url where we want to POST
          data: formData, // our data object
          dataType: 'json' // what type of data do we expect back from the server
  
      })
      // using the done promise callback
      .done(function (data) {
          console.log("ajax done callback");
      })
      .fail(function (data) {
          console.log(data, "ajax failed callback");
  
          var IS_JSON = true;
          try {
              var json = $.parseJSON(data);
          } catch (err) {
              IS_JSON = false;
          }
          console.log(IS_JSON);
      });
  </code></pre>