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.
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!!!!
- // Live check
- function check_name() {
- var username = $("#username").val();
- if(username.length > 5) {
- $("#availability_status").html('<?php echo $strAvChk; ?>'); // Checking availability...
- jQuery.ajax({
- type: "POST",
- url: '/inc/check_chain.php', // tracking special characters
- data: "u="+ username +"&st=5",
- global: false, // fixed it!
- cache: false,
- success: function(response) {
- if(response == 1) {
- jQuery.ajax({
- type: "POST",
- url: "/inc/usr_chk.php", // checking database if available
- data: "u="+ username,
- cache: false,
- success: function(response){
- $("#availability_status").ajaxComplete(function(event, request){
- if(response == 1){
- usrnm = 0;
- $("#availability_status").html('<?php echo $strAvNo; ?>'); // not available
- } else {
- usrnm = 1;
- $("#availability_status").html('<?php echo $strAvOk; ?>'); // available
- }
- });
- }
- });
- } else {
- usrnm = 0;
- $("#availability_status").html('<?php echo $strAvNo; ?>'); // contains forbidden characters
- }
- }
- });
- } else {
- usrnm = 0;
- $("#availability_status").html('<?php echo $strAvSh; ?>'); // username too short
- }
- }