我想限制使用密码访问write.php
,但密码应该是另一个页面上的jquery ajax方法(index.php)。
index.php
<div id="btnsNo">
<img class="btNo" id='n0' src="btns/num0.png" alt="num">
<img class="btNo" id='n1' src="btns/num1.png" alt="num">
<img class="btNo" id='n2' src="btns/num2.png" alt="num">
<img class="btNo" id='n3' src="btns/num3.png" alt="num">
<img class="btNo" id='n4' src="btns/num4.png" alt="num">
<img class="btNo" id='n5' src="btns/num5.png" alt="num">
</div>
js
pass = '';
$('.btNo').click(function(){
$a = $(this).attr('id');
$b = $a.substring(1);
pass = pass + $b;
alert (pass); // works well till here
$.ajax({
url : 'pass.php',
type : 'post',
data : { pass : pass }
});
});
pass.php
$pass01 = 1405;
$pass02 = $_POST['pass'];
if ($pass01 = $pass02){
header('Location: write.php');
}
我点击.btnNo
所以pass
是1405
- 但没有任何反应。我希望重定向到write.php
。
答案 0 :(得分:0)
应该是
if ($pass01 == $pass02){
echo "1";
}else{
echo "0";
}
脚本:
$(function(){
pass = '';
$('.btNo').click(function(){
$a = $(this).attr('id');
$b = $a.substring(1);
pass = pass + $b;
alert (pass); // works well till here
$.ajax({
url : 'pass.php',
type : 'post',
data : { pass : pass }
}).done(function( data ) {
if(data==1){
window.location='write.php';
}
});
});
});