Request ok, return not ok

Request ok, return not ok

EDIT : Solved 

Hi there,

I've been spinning around for 2 days now so I decided to beg the community for help lol

I'm coding a live username checker and I have a problem with the data returned by my Ajax request.

( http://www.youtube.com/watch?v=9owt8HnO4dI I made a video, sorry it's in french but even without the audio, the video pretty clearly explain itself)

I have three pages :
- registration.php // registration form
- chain_check.php // check for forbidden special characters
- usr_chk.php // check into the database if the username is available

Problem : when the user enters his username, onBlur the function check_name is called and returns if there's a problem (chain_check or usr_chk) but then, if he edits it, the function is called, the response is correct (as I can see with firebug) but it's not updated on the screen and the validation var either (usrnm) :(

Here's my code, it's pretty clean so if you could tell me what's wrong with it, I could go further 

Thanks!!!!

  1. // Live check
  2. function check_name() {
  3.       var username = $("#username").val();
  4.             if(username.length > 5) {
  5.             $("#availability_status").html('<?php echo $strAvChk; ?>'); // Checking availability...
  6.                         jQuery.ajax({
  7.                         type: "POST",
  8.                         url: '/inc/check_chain.php', // tracking special characters
  9.                         data: "u="+ username +"&st=5", 
  10.                         global: false, // fixed it!
  11.                         cache: false,
  12.                         success: function(response) {
  13.                                     if(response == 1) { 
  14.                                     jQuery.ajax({
  15.                                     type: "POST",  
  16.                                     url: "/inc/usr_chk.php", // checking database if available
  17.                                     data: "u="+ username,
  18.                                     cache: false,     
  19.                                     success: function(response){  
  20.                                                 $("#availability_status").ajaxComplete(function(event, request){
  21.                                                 if(response == 1){
  22.                                                 usrnm = 0;
  23.                                                 $("#availability_status").html('<?php echo $strAvNo; ?>'); // not available
  24.                                                 } else {
  25.                                                 usrnm = 1;
  26.                                                 $("#availability_status").html('<?php echo $strAvOk; ?>'); // available
  27.                                                 }
  28.                                           }); 
  29.                                     }
  30.                               });
  31.                         } else {
  32.                         usrnm = 0;
  33.                         $("#availability_status").html('<?php echo $strAvNo; ?>'); // contains forbidden characters
  34.                         }
  35.                   }
  36.             }); 
  37.             } else {
  38.             usrnm = 0;
  39.             $("#availability_status").html('<?php echo $strAvSh; ?>'); // username too short
  40.             }
  41. }