我已经'克隆'了一个脚本,除了变量脚本与原始脚本完全相同!但它并没有完全奏效。它陷入了困境:
if(validConnection=="")
{
$('#UsernameConnection').css('border-color','#00ff00');
$('.ErrorUsernameConnection').text('');
checkUsername1 = true;
}
(其余代码在下面)
我一直在检查我是否在更改可变电源时犯了一些错误,但它们似乎都匹配得当。怎么了?如何使用不同的变量才能正常工作,而不是这次???
这是HTML:
<div id="Connection">
<div class="Connection">
Connection
<a href="#" id="HideConnection"><strong>×</strong></a>
</div>
<?php connection(); ?>
<div class="formConnection">
<form method="POST" autocomplete="off" name="Connection">
<label for="Connection">Username:</label><br/>
<input type="text" name="UsernameConnection" id="UsernameConnection"/><br/>
<span class="ErrorUsernameConnection"></span><br/>
<label for="Connection">Password:</label><br/>
<input type="password" name="PasswordConnection" id="PasswordConnection"/>
<span class="ErrorPasswordConnection"></span><br/>
<input type="checkbox" name="checkbox"/><label>Remember me</label><br/>
<input type="submit" name="Connection" value="Log In" id="Connection" class="LogIn"/>
</form>
</div>
这是php:
<?php
if(isset($_POST['UsernameConnection']))
{
$Username1 = $_POST['UsernameConnection'];
if(preg_match("/^([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿ]{1,}[._-\s]?)+[a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿ]{1,}$/",$Username1))
{
echo "";
}else
{
echo "Invalid";
}
}
?>
和JS:
$(document).ready(function(){
var checkUsername1 = false;
$('#UsernameConnection').keyup(function(){
var Username1 = $('#UsernameConnection').val();
if(Username1=="")
{
$('#UsernameConnection').css('border-color','red');
$('.ErrorUsernameConnection').text('Error message 1');
checkUsername1 = "Username empty";
}else
{
$.post('fonctions/validUsernameConnection.php',{Username1:Username1},function(validConnection)
{
$('.ErrorUsernameConnection').text(validConnection);
if(validConnection=="")
{
$('#UsernameConnection').css('border-color','#00ff00');
$('.ErrorUsernameConnection').text('');
checkUsername1 = true;
}else
{
$('#UsernameConnection').css('border-color','orange');
checkUsername1 = "Username Invalid";
}
});
}
});
});
PS:我对所有堆栈的网站都有点失落所以请原谅我,如果这不是正确的发布这个= /
答案 0 :(得分:0)
问题似乎出在这一行
$.post('fonctions/validUsernameConnection.php',{Username1:Username1},
function(validConnection)
在你的PHP中你应该检查$ _POST ['Username1']而不是$ _POST ['UsernameConnection']