weixin_42526032 2018-12-05 11:44 采纳率: 0%
浏览 665

返回前台的值老是空的怎么回事??有没有大神,跪求帮忙

<?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);

}

  • 写回答

6条回答 默认 最新

  • threenewbee 2018-12-05 14:19
    关注

    var post_data = {user:user,pwd:pwd};
    这么写不对吧
    var post_data = {"user":user,"pwd":pwd};
    看看

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作