jQuery:检查用户名可用性 [英] jQuery: check username availability
问题描述
在我的Web应用程序上注册时,我正在使用jQuery检查用户名的可用性.由于某种原因,而不是将用户数据保留在数据库中,我将注册用户的ID和密码存储在平面文件account.txt中.格式如下:
I am using jQuery to check username availability when registering on my web application. For some reason, rather then to keep user data in database, I store the registered users's ID and password in a flat file accounts.txt. The format is like this:
joe:frt25t5546g
john:sdfsdgg
joe:frt25t5546g
john:sdfsdgg
更新
Thanks to the help of guys here, I finally got a clue on it, I followed the method on http://roshanbh.com.np/2008/04/check-username-available-ajax-php-jquery.html.
这是我registration.html的一部分
Here is part of my registration.html
$(document).ready(function()
{
$("#uname").blur(function(){
$.post("usernameCheck.php",{user_name:$(this).val()},function(data)
{
if(data=="no"){
$(this).html("This username already exists");
}
else{
$(this).html("Username is available!");
}
});
});
}
<body>
<form name="form" method="post" action="" />
<table>
<tr><td>Username: </td>
<td><input type="text" name="uname" id="uname" /></td></tr>
</table>
<input type="submit" name="submit" value="Register" />
</form>
</body>
我对jQuery很陌生,对ajax有点...谢谢!
I am quite new to jQuery, ajax sort of things...Thanks!
推荐答案
不要在客户端执行此操作.您的密码,即使是加密的,也永远不会离开您的服务器.制作一个服务器端脚本,该脚本将接受用户名并返回一个布尔值,然后通过AJAX进行调用.
Don't do this on clientside. Your passwords, even encrypted, should never leave your server. Make a serverside script that will accept a username and return a boolean, then call it through AJAX.
另外,要回答您的直接问题,请查找JavaScript方法String.split
和String.match
.
Also, to answer your direct question, look up JavaScript methods String.split
and String.match
.
这篇关于jQuery:检查用户名可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!