用户名检查页面

I'm creating a system that checks (via AJAX) if a given username is already taken. If so, then it alerts the user accordingly. I'm basing my system off of this tutorial and have tried adapting it to my site.

$(document).ready(function()//When the dom is ready
{
  $("#username").change(function()
  { //if theres a change in the username textbox

    var username = $("#username").val();//Get the value in the username textbox
    if(username.length > 3)//if the lenght greater than 3 characters
    {
      $("#availability_status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');
      //Add a loading image in the span id="availability_status"

      $.ajax({  //Make the Ajax Request
        type: "POST",
        url: "ajax_check_username.php",  //file name
        data: "username="+ username,  //data
        success: function(server_response){

          $("#availability_status").ajaxComplete(function(event, request){

            if(server_response == '0')//if ajax_check_username.php return value "0"
            {
              $("#availability_status").html('<img src="available.png" align="absmiddle"> <font color="Green"> Available </font>  ');
              //add this image to the span with id "availability_status"
            }
            else  if(server_response == '1')//if it returns "1"
            {
              $("#availability_status").html('<img src="not_available.png" align="absmiddle"> <font color="red">Not Available </font>');
            }

          });
        }

      });

    }
    else
    {

      $("#availability_status").html('<font color="#cc0000">Username too short</font>');
      //if in case the username is less than or equal 3 characters only
    }
    return false;
  });
});

ajax_check_username.php - HERE's where I think I'm having problems!!

<?php
include ("inc/db/db.php");

if($stmt = $mysqli->prepare('SELECT NULL FROM `bruger` WHERE `brugernavn` = ?'))
{
  $stmt->bind_param('s', $brugernavn);
  $brugernavn = $_POST["brugernavn"];
  $stmt->execute();
  $stmt->store_result();
  $count = $stmt->num_rows;
  $stmt->close();
  if($count = 0)
  {
    echo '1';
  }
  else
  {
    echo '2';
  }
}
?>


<tr>
  <td><p>Brugernavn</p></td>
  <td><input type="text" name="brugernavn" id="username"></td>
  <td><span id="availability_status"></span></td>
</tr>

ATTENTION I think I've made mistakes in my php, so it may be why it does not bother to do what I want it .. but it's just when I think.

This is what my html looking for when I need to check user name in the database. this is how I get no errors at all. it must be said that I never play with ajax or javascript before. so it will be a great help if you could help me further.

Feel free to ask if there is more you want to know something.

This if($count = 0) should be if($count == 0) if that affects your logic.

You're assigning $brugernavn after you're using it.

$stmt->bind_param('s', $brugernavn);
$brugernavn = $_POST["brugernavn"];

Using ajaxComplete is not useful here:

$("#availability_status").ajaxComplete(function(event, request){

You are assigning where you should be comparing:

if($count = 0)

Your Javascript expects a 0 or 1, but your PHP script outputs one of 1 or 2.