Menu icon Foundation
problem, Ajax in Abide form validation

I make form validation by use ajax but, when "result = true" red bar is not turn off.
I think may me have issue at ajax code.
Please hlep me for look my code.

Thank you so much

 $(document).foundation({
         abide: {
            validators: {
               myValidator: function(el, required, parent) {
                  var emptyStringRegEx = /^$/;
                  var validRegExp = /^[A-Za-z ]+$/;
                  var result = false;                  
                  if (emptyStringRegEx.test(el.value.trim())) {
                     console.log("The input is empty. Input value: '" + el.value + "'");
                     if (required) {
                        $("#error_message").text("กรุณากรอก");
                     }
                     else {
                        result = true;
                     }
                  }
                  else {
                     if (validRegExp.test(el.value)) {
                        if ((el.value).length > 6) {
    						var Username = $('#logname').val()
							var UsernameAvailResult = $('#username_avail_result');
							UsernameAvailResult.html('Loading..');
							var UrlToPass = 'action=username_availability&logname='+Username;
                            var getData= $.ajax({ 
						
                        			type : 'POST',
                        			data : UrlToPass,
                        			url  : 'modifly/registerchecker.php',
	                        		success: function(responseText){ // Get the result and asign to each cases
                                        if(responseText > 0){
	                        				$("#error_message").text("คนใช้แล้ว");
											
	                        			}
	                        			else {
	                        			result = true; 
						
	                        			}
	                        			
		                        	}
	                        		});
                     }
                     else {
                         console.log("The input is invalid. Input value: '" + el.value + "'");
                        $("#error_message").text("กว่ากว่า 7");
                     }
                     }
                     else {
                        console.log("The input is invalid. Input value: '" + el.value + "'");
                        $("#error_message").text("ตัวอักษรเท่านั้น");
                     }
                  }
				  
				  
                  return result;
               }
            }
         }
      });

   
   
   
   
            

         

AJAXabide

I make form validation by use ajax but, when "result = true" red bar is not turn off.
I think may me have issue at ajax code.
Please hlep me for look my code.

Thank you so much

 $(document).foundation({
         abide: {
            validators: {
               myValidator: function(el, required, parent) {
                  var emptyStringRegEx = /^$/;
                  var validRegExp = /^[A-Za-z ]+$/;
                  var result = false;                  
                  if (emptyStringRegEx.test(el.value.trim())) {
                     console.log("The input is empty. Input value: '" + el.value + "'");
                     if (required) {
                        $("#error_message").text("กรุณากรอก");
                     }
                     else {
                        result = true;
                     }
                  }
                  else {
                     if (validRegExp.test(el.value)) {
                        if ((el.value).length > 6) {
    						var Username = $('#logname').val()
							var UsernameAvailResult = $('#username_avail_result');
							UsernameAvailResult.html('Loading..');
							var UrlToPass = 'action=username_availability&logname='+Username;
                            var getData= $.ajax({ 
						
                        			type : 'POST',
                        			data : UrlToPass,
                        			url  : 'modifly/registerchecker.php',
	                        		success: function(responseText){ // Get the result and asign to each cases
                                        if(responseText > 0){
	                        				$("#error_message").text("คนใช้แล้ว");
											
	                        			}
	                        			else {
	                        			result = true; 
						
	                        			}
	                        			
		                        	}
	                        		});
                     }
                     else {
                         console.log("The input is invalid. Input value: '" + el.value + "'");
                        $("#error_message").text("กว่ากว่า 7");
                     }
                     }
                     else {
                        console.log("The input is invalid. Input value: '" + el.value + "'");
                        $("#error_message").text("ตัวอักษรเท่านั้น");
                     }
                  }
				  
				  
                  return result;
               }
            }
         }
      });

   
   
   
   
            

         
puriphat over 5 years ago

// registerchecker.php
<?
header('Content-Type: text/html; charset=utf-8');
include("../userdb.php");
mysql_query("set NAMES utf-8");
if(isset($_POST['action']) && $_POST['action'] == 'username_availability'){ // Check for the username posted
$username = htmlentities($_POST['logname']); // Get the username values
$check_query = mysql_query('SELECT logname FROM userinfo WHERE logname = "'.$logname.'" '); // Check the database
echo mysql_num_rows($check_query); // echo the num or rows 0 or greater than 0
}

?>

hiousi over 5 years ago

try $.ajax({ async: false })