gpt4 book ai didi

javascript - 如何通过AJAX、PHP传递复选框值?

转载 作者:太空宇宙 更新时间:2023-11-04 16:21:45 25 4
gpt4 key购买 nike

我有一个简单的登录表单,带有复选框“记住我”。我想要实现的是,当用户选中复选框而不是创建 cookie 时,否则启动 session ,但即使我选中复选框,它仍然会启动 session 。有人可以帮忙吗?

这是我的 html:

<form action="PHP/login.php" method="post" class="loginForm">

<div class="form_vkope">
<input type="text" name="prihlNick" placeholder="Nick" class="prihlNick" />
<img src="Obrazky/ios7-person.png" alt="Ikonka postavy">
</div>

<div class="form_vkope">
<input type="password" name="prihlHeslo" placeholder="Heslo" class="prihlHeslo" />
<img src="Obrazky/locked.png" alt="Ikonka zámok">
</div>


<div class="obal_submitov">
<input type="checkbox" name="zapametat" class="zamapetat" /><label for="zapametat"><span></span>Remember me</label>
<input type="submit" name="prihlasit" value="Login" class="prihlasit" />
</div>
</form>

我的 PHP 的一部分:

$zapametat = $_POST['zapametat']; //checkbox
if ($dbNick == $Snick AND $dbHeslo == $Sheslo) {
if ($ban != 1) {
if (isset($zapametat)) {
setcookie('id',$dbId,time()+86400, '/');
setcookie('nick',$dbNick,time()+86400, '/');
echo "cookie";
}else{
$_SESSION['id'] = $dbId;
$_SESSION['nick'] = $dbNick;
echo "session";
}
}else{
echo "Tvoj účet bol zablokovaný";
}
}else{
echo "Heslo alebo meno sa nezhoduje";
}
}

还有我的 jQuery:

$('.prihlasit').click(function() {
var prihlNick = $('.prihlNick').val();
var prihlHeslo = $('.prihlHeslo').val();
var prihlasit = $('.loginForm .prihlasit');
var checbox = $('.zapametat'); //checkbox
var data = 'prihlNick='+prihlNick+'&prihlHeslo='+prihlHeslo+'&zapametat='+checbox+'&prihlasit='+prihlasit;
if (prihlNick == '' || prihlHeslo == '') {
$('.loginForm :input').addClass('inputError');
}else{
$('.loginForm :input').removeClass('inputError');
$.ajax({
url: 'PHP/login.php',
type: 'POST',
data: data ,
})
.done(function(data) {
$('.vypis_chyba').html(data);
console.log(data);
})
}
});

最佳答案

我建议使用这个:

jQuery

var checbox = $('.zapametat').prop('checked'); //checkbox (jQuery 1.6+)

PHP

if((isset($zapametat))&&($zapametat==true)){

关于javascript - 如何通过AJAX、PHP传递复选框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40577452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com