php - Change class after depending on received data? -


i have jquery script sends request check_username.php checks in database if username available , echoes true or false , it's working.

however when type form username doesn't exists form turns green, good, once enter username exists turns form red , no matter username type stay red.

how solve this?

jquery

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script>   $(document).ready(function() {         $("#username").keyup(function(e) {               var username = $("#username").val();                     $.post('check_username.php', {'username': username}, function(data) {                           if(data=="true") {                                 $("#usergroup").addclass("input-group has-error");                           } else if(data=="false"){                                 $("#usergroup").addclass("input-group has-success");                           }                     });         });   }); </script> 

check_username.php

<?php include 'includes\\connect.inc.php';  if(isset($_post['username'])) {       $username = $_post['username'];             $query = "select id users username='$username'";             $query_run = mysql_query($query);                   if($query_run) {                         $query_num_rows = mysql_num_rows($query_run);                               if($query_num_rows==1) {                                     echo "true";                               } elseif($query_num_rows==0) {                                     echo "false";                               }                   } }  ?> 

connect.inc.php

<?php $mysql_error = mysql_error();  $mysql_database = 'codeforum'; $mysql_host = '127.0.0.1'; $mysql_user = 'root'; $mysql_pass = '';  if(!mysql_connect($mysql_host, $mysql_user, $mysql_pass) || !mysql_select_db($mysql_database)) {     die($mysql_error); }  ?> 

figured out, using focus event didnt wanted, event keydown fixed it!


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -