显示一些关于用户名的选项

时间:2013-06-09 06:52:27

标签: php javascript cakephp

当我们在订阅网站时尝试输入用户名时,它将拒绝我们的选择并向我们显示一些可由我们选择的用户名。例如,如果我放了Junaid,该网站会向我显示选项Junaid1123,Junaid444 ......我怎么能为我的网站做到这一点?

1 个答案:

答案 0 :(得分:1)

1) Use javascript to get the entered username from the form.
2) Send a synchronous ajax request containing the entered username to a program on your server.
3) Have your server program check if the entered username is in your database.
3) If the entered username is not in your database, then create an array of 5 random numbers.
4) Create an array of 5 strings, where each string consists of the username added to each of the random numbers.
5) Check your db for the 5 usernames, and eliminate any that already exist.  Create more as necessary. 
6) Send back five usernames in the response.
7) Use js to display the five names to the user.