<?php
namespace app\index\controller;
use think\Controller;
header("Content-type: text/html; charset=utf-8");
class Index extends Controller
{
public function index()
{
return $this->fetch();
}
function send_msg($status,$msg){
$res["status"]=$status;
$res["msg"]=$msg;
echo json_encode($res);
exit;
}
function login(){
$user = $_POST["user"];
$password = $_POST["pwd"];
if (empty($user)){
$this->send_msg(-1,"请输入账号");
}
if (empty($pwd)){
$this->send_msg(-1,"请输入密码");
}
$where["name"]=$user;
$info = DB("user")
->where($where)
->find();
if (empty($info)){
$this->send_msg(-1,"用户xxx");
}
if ($info["password"]!=$password){
$this->send_msg(-1,"密码xx");
}
$this->send_msg(1,"完美");
echo "okokok";
}
}
//js代码
function login(){
var user = $("#user").val();
var pwd = $("#pwd").val();
var post_data = {user:user,pwd:pwd};
var data = {url:"/index.php/index/Index/login",
data:post_data,
type:"post",
dataType:"json",
success:function(res){
if(res.status == -1){
alert(res.msg);
}
if(res.status == 1){
alert(res.msg);
}
}};
$.ajax(data);
}