我有一个代码,其中有一个函数应该检查用户名是否可用。
我对这个功能的工作原理感到困惑。
JS:
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery("#register-form").validationEngine();
});
HTML 输入:
<form action="" id="register-form">
<input value="" class="validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxNameCallPhp]]] input" type="text" name="username"/>
</form>
这是我的 JS 函数:
(function($){
$.fn.validationEngineLanguage = function(){};
$.validationEngineLanguage = {
newLang: function(){
$.validationEngineLanguage.allRules = {
"ajaxNameCallPhp": {
// remote json service location
"url": "ajaxNameCallPhp.php",
// error
"alertText": "* This name is already taken",
// speaks by itself
"alertTextLoad": "* Validating, please wait"
}
};
}
};
$.validationEngineLanguage.newLang();
})(jQuery);
这是我的ajaxNameCallPhp.php
功能:
include ("config.php");
$username = trim(strtolower($_POST['username']));
$username = mysql_escape_string($username);
$query = "SELECT username FROM user WHERE username = '$username' LIMIT 1";
$result = mysql_query($query);
$num = mysql_num_rows($result);
echo $num;
mysql_close();
所以任何人都可以给我一个解决方案?
我感谢并感谢您的关注。
谢谢你。