Q: jquery val() and serialize() Problem: 
When i use .serialize(), it works fine as I want .
When i use .val(), it shows on console:
failed 
admin 

admin is username, but jquery does not get echo from php i think
Jquery file
$(document).ready(function() {
$('#username').blur(function(event) {
      // var submitData = $('#login_form').serialize();
        var username=$("#username").val();
        $.ajax({
          url: './checkUsername.php',
          type: 'POST',
          data: username
        })
        .done(function(res) {
          if (res == 1) {
            $('#checkUsername').html("User exists");
            console.log("success");
          } else {
            $('#checkUsername').html("User do not exists");
            console.log("failed");
            console.log(username);
          }

        })});

Php file
<?php
require_once 'config.php';

$username = $_POST['username'];

$query = "select * from members where username='$username'";

if ($stmt = mysqli_prepare($con, $query)) {
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);

    if (mysqli_stmt_num_rows($stmt) == 1) {
        echo 1;
    } else {
        echo 0;
    }

    mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>


A: You're only sending a value:
data: username

But the server-side code expects a key/value pair:
$_POST['username']

Send an object with a key for that value:
data: { username: username }


A: change data: username to {username: username}
as passing of data requires an index.
know more about jquery post http://api.jquery.com/jquery.post/
