码迷,mamicode.com
首页 > Web开发 > 详细

test_ThinkPHP+AJAX

时间:2016-05-28 15:59:59      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

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

 

test_ThinkPHP+AJAX

标签:

原文地址:http://www.cnblogs.com/sihuiming/p/5537446.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!