代码如下
<body class="login_bg">
<form id="admin_form" class="login_main" id="login_main" action="/index.php" method="post">
<div class="login_name">
<label for="login_name">用户名:</label>
<input type="text" id="login_name" name="login_name" >
</div>
<div class="login_password">
<label for="login_password">密 码:</label>
<input type="password" id="login_password" name="login_password" >
</div>
<div class="login_buttons">
<input id="login_submit" type="button" value="登陆" />
<input type="reset" value="重置" />
</div>
<input type="hidden" name="m" value="admin" />
<input type="hidden" name="c" value="login" />
<input type="hidden" name="a" value="login" />
</form>
<script src="/Public/js/jquery-3.1.1.min.js"></script>
<script src="/Public/js/bootstrap.min.js"></script>
<script type="text/javascript">
$("#login_submit").bind("click",function(){
var type = "post";
var url = "index.php?m=admin&c=index&a=checkLogin";
var formArrays = $("#admin_form").serializeArray();
var requestData = {};
for(var i=0; i<formArrays.length;i++){
//requestData[formArrays[i].name] = formArrays[i].value;
//console.log(typeof formArrays[i].name);
requestData[formArrays[i].name] = formArrays[i].value;
}
// 如果使用{ name: "John", time: "2pm" } 跳转通过$_POST 获取到的值没有问题,但是如果是上面的requestData 则会返回当前页面的html
//requestData = { login_name: "John", login_password: "2pm",m:"admin",c:"index",a:"checkLogin" };
console.log(typeof requestData);
var dataType = "json";
$.post(url,requestData,function(data){alert(data);});
});
</script>
</body>
咕咕问
Caballarii
相关分类