title: Retrieve JSON data for authentication
body: <p>I am trying to make a login authentication using php to match the username and password and echo it as a JSON object. </p>
  
  <p>The form is to be sent using ajax and also read the returned JSON data. This is the part I am having trouble with. </p>
  
  <p>My html looks like this:</p>
  
  <pre><code>&lt;form id='logform' method='post' &gt;
     &lt;label for="username"&gt;User Name:&amp;nbsp;&lt;/label&gt;&lt;input id='user_name' type='text' name='username' required placeholder='User Name' /&gt;
     &lt;label for="password"&gt;Password:&amp;nbsp;&lt;/label&gt;&lt;input type='password' placeholder="Password" name='password' id="password" required /&gt;
     &lt;input type="submit" name="submit" id="login" value="Log In"  /&gt;
     &lt;input type="button" id="cancel_hide" value="Cancel" /&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>sendLogDetails.php:</p>
  
  <pre><code>&lt;?php
   include("dbconnect.php");
   $numrows=0;
   $password=$_POST['password'];
   $username=$_POST['username'];
  
   $query="select username, fname, lname, memcat from members where (username='$username' &amp;&amp; password='$password')";
  $link = mysql_query($query);
  if (!$link) {
   echo 3;
    die();
   }
  
   $numrows=mysql_num_rows($link);
   if ($numrows&gt;0){  // authentication is successfull
   $rows = array();
   while($r = mysql_fetch_assoc($link)) {
   $rows[] = $r;
  }
  $json=json_encode($rows);  
  echo $json;
  } else {
  echo 3;  // authentication was unsuccessfull
  }
  ?&gt;
  </code></pre>
  
  <p>And the jQuery is as follows:</p>
  
  <pre><code>$("#login").click(function(){
  
      username=$("#username").val();
      password=$("#password").val();
  
       $.ajax({
          type: "POST",
          url: "scripts/sendLogDetails.php",
          data: "username="+username+"&amp;password="+password,
          success: function(html){
            if(html=='true')
            {
              sessionStorage.setItem("user", $("#username").val());
            }
  
            else
            {
                  $("#add_err").html("Wrong username or password");
            }
  
          },
  
      });
       return false;
  });
  </code></pre>
  
  <p>The above code sends through the username and password and when I check the response in my console log it shows the data from the queried table. I am wondering how I can then retrieve this data to set it in session storage???</p>