首页 > 代码库 > 验证信息json返回,前台接收显示无刷新。笔记

验证信息json返回,前台接收显示无刷新。笔记

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>欢迎登录后台管理系统</title>
<link href="/css/style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="/js/jquery.js"></script>
<script src="/js/cloud.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
 $(function(){
  $("#send").click(function(){
   var cont = $("input").serialize();
   $.ajax({
    url:"{:url(‘Index/login‘)}",
    type:post,
    dataType:json,
    data:cont,
    success:function(data){
     var str = data.msg;
     $("#result").html(str);
    }
   });
  });  
 });
</script>
<script language="javascript">
    $(function() {
        $(.loginbox).css({
            position : absolute,
            left : ($(window).width() - 692) / 2
        });
        $(window).resize(function() {
            $(.loginbox).css({
                position : absolute,
                left : ($(window).width() - 692) / 2
            });
        })
    });
</script>

</head>

<body
    style="background-color: #1c77ac; background-image: url(images/light.png); background-repeat: no-repeat; background-position: center top; overflow: hidden;">



    <div id="mainBody">
        <div id="cloud1" class="cloud"></div>
        <div id="cloud2" class="cloud"></div>
    </div>


    <div class="logintop">
        <span>欢迎登录后台管理界面平台</span>
        <ul>
            <li><a href="#">回首页</a></li>
            <li><a href="#">帮助</a></li>
            <li><a href="#">关于</a></li>
        </ul>
    </div>

    <div class="loginbody">

        <span class="systemlogo"></span>
         <div id="result">一会看显示结果</div>
<form name="form1" method="post" action="">
        <div class="loginbox">

            <ul>
                <li><input name="username" type="text" class="loginuser" 
                    onclick="JavaScript:this.value=http://www.mamicode.com/‘‘" /></li>
                <li><input name="password"  type="password" class="loginpwd" 
                    onclick="JavaScript:this.value=http://www.mamicode.com/‘‘" /></li>
                            <li>
                            
                            <input name="checkcode"  type="text" class="logincheck" 
                    onclick="JavaScript:this.value=http://www.mamicode.com/‘‘" />
                    
                    
            <label style="margin-top:10px">        <img src="{:captcha_src()}"  alt="captcha"  name="captcha" onclick="javascript:this.src=http://www.mamicode.com/‘{:captcha_src()}?tm=‘+Math.random();" 
                    
                    
                    /></label>
                    
                    
                    </li>
                    
                <li><input name=""  type="button"  class="loginbtn" value="登录"  id="send"/><label>
                    <input
                        name="" type="checkbox" value="" checked="checked" />
                        记住密码</label><label>
                        <ahref="#">忘记密码?</a></label></li>
            </ul>


        </div>
</form>
    </div>
</body>

</html>

 

 控制器简单的返回json格式

    public function login(){
        $request=Request::instance();
        $params=$request->param();
     //   echo "username is:".$params[‘username‘];
      $validate= Validate_Data::loginValidata($params);
      if(!$validate->check($params)){
       //   return       json(["info"=>$validate->getError()]);正确的

 

错误信息

验证信息json返回,前台接收显示无刷新。笔记