ThinkPHP+AJAX

TestController.class.php

<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends Controller{
    
        public function test()
    {
        
            if(empty($_POST))
        {
            $this->display();
        }
            else
        {
            $code = I('code');
        
            $sheng = M('sheng');
            
            $name = $sheng->where("sheng_id = '{$code}'")->find();
            
            $this->ajaxReturn($name);
            
            
        }
    }
}

?>
View Code

test.html

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="__PUBLIC__/JQ/jquery-1.12.4.min.js"></script>
</head>
<body>
<div>代号:<input type="text" id="code"></div>
<input type="button" value="显示" id="btn">
<div id="aa"></div>

</body>
</html>
<script type="text/javascript">

$(document).ready(function(e) {
    
    $("#btn").click(function(e) {
        
    var code = $("#code").val();
    
    $.ajax({
        
              url:"__SELF__",
              data:{code:code},
              dataType:"json",
              type:"POST",
              success: function(data){
            
                 $("#aa").html(data.sheng_name);
                  
                  }
            })

        });
});

</script>
View Code

 

posted @ 2016-05-28 15:03  司会铭  阅读(324)  评论(0编辑  收藏  举报