2
我正在使用yii2-advanced-app &想要使用post方法向我的siteController发送用户名&密码。我不想在这里使用隐藏的表单域。Yii2:从控制器中弹出数值
<form id = "userlogin" action = "index.php?r=site/loginpopup" method = "POST">
<label>Email/Username</label>
<input type="text" name="username" id="username"/>
<br />
<label>Password</label>
<input type="password" name="password" id="password"/>
<br />
<div class="checkbox">
<input id="remember" type="checkbox" />
<label for="remember">Remember me on this computer</label>
</div>
<div class="action_btns">
<div class="one_half"><a href="#" class="btn back_btn"><i class="fa fa-angle-double-left"></i> Back</a></div>
<div class="one_half last"><input type="submit" value="Search" onclick="getCred()"><a href="javascript: getCred()" name='login-button' class="btn btn_red">Login</a></div>
</div>
</form>
<script type="text/javascript">
var userloginValidator = new Validator("userlogin");
userloginValidator.addValidation("username","req", "Please enter the value for query");
function getCred(){
var un = document.getElementById('username').value;
var pwd = document.getElementById('password').value;
alert(un);alert(pwd);
// window.location = "index.php?r=site/loginpopup&username="+un+"&password="+pwd;
if(document.userlogin.onsubmit()) {
document.userlogin.submit();
}
$.post("index.php?r=site/loginpopup", { username: un }, { password: pwd });
// jQuery.post('index.php?r=site/loginpopup',{ username: un }, { password: pwd });
}
</script>
而且控制器的功能是 - -
public function actionLoginpopup()
{
$un = $_POST['username'];
echo $un;
exit();
}
但是,它说
我弹出位于index.php文件是:
我这样试了一下 -
错误的请求(#400) 无法验证您的数据提交。