用于检查用户名可用性的Javascript帖子无效
16lz
2021-01-22
Im trying to check if the register username's available but everytime the clientside returns that the username its available.
我试图检查注册用户名是否可用,但每次客户端返回该用户名可用时。
This is my clientside code:
这是我的客户代码:
$(document).ready(function()
{
$("#register_username").blur(function(){
var user = $("#register_username").val();
$.post("register",
{
username: user
},
function(data, status){
if(data == '1')
{
alert('Good, username its available!');
}
else
{
alert('Snap!You cant use this username :(!');
}
});
});
});
And this is the serverside code:
这是服务器端代码:
if(strlen($_POST['username']) > 0)
{
$usr = $_POST['username'];
if($usr == 'test')
echo '1';
else
echo '2';
}
PHP Version: 5.5
PHP版本:5.5
1 个解决方案
#1
first of all, i guess if the input field has value "test" it would say "you cannot use this username"?
首先,我猜如果输入字段的值为“test”,它会说“你不能使用这个用户名”?
in your code if input is "test" ($usr == "test" - that comes from input)
you echo 1
, and in your code 1 means username is available? So shouldn't it be backwards?
在你的代码中如果输入是“test”($ usr ==“test” - 来自输入)你回显1,在你的代码1中意味着用户名是否可用?所以它不应该倒退吗?
Does it say "username is available" with every input?
每次输入都会说“用户名是否可用”?
更多相关文章
- 指导我优化我的PHP代码,用数组中的空数据填充缺失值
- 分叉开源PHP代码,项目类加载器策略
- 用Hack编写的代码比在HHVM上用PHP编写的代码更快吗?
- [php]在PHP中读取和写入WORD文档的代码
- php评论回复无限极嵌套如何实现?已写基本代码,期待高手解惑
- advertising.php源代码分析
- thinkphp友情链接代码
- 如何在php中找到更轻或更暗版本的十六进制代码的十六进制代码
- 如何使用用户名作为子域名创建子域?