【发布时间】:2016-01-19 11:44:57
【问题描述】:
我正在使用 yii2-advanced-app 并且想使用 post 方法将用户名和密码发送到我的 siteController。我不想在这里使用隐藏的表单域。
我是这样尝试的:
我在 index.php 中的弹出窗口是 -
<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();
}
但是,它说——
错误请求 (#400) 无法验证您提交的数据。
【问题讨论】:
标签: php post http-post yii2-advanced-app