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

2016/05/17 thinkphp3.2.2 ① Ajax 使用 ②前端验证

时间:2016-05-17 17:23:53      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

显示效果:

技术分享技术分享

 

 

 

①Ajax使用:   注意传值的所有过程用的是小写,及时数据库列的名称中有大写字母

控制器部分:

AjaxController.class.php

 1 <?php 
 2 namespace Home\Controller;
 3 use Think\Controller;
 4 class AjaxController extends Controller
 5     {
 6 
 7         public function Ajax(){
 8 
 9             if (empty($_POST)) {
10                 $this->display();
11             }
12             else{
13                 $code=$_POST["code"];
14                 $nation=D(‘nation‘);
15                 $attr=$nation->find($code);
16                 $name=$attr["name"];
17                 $this->ajaxReturn($name,‘eval‘);
18 
19             }
20         } 
21 
22 
23     }

②Ajax.html 

技术分享
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <script src="../../../../../jquery-1.11.2.min.js"></script>
 7 </head>
 8 <body>
 9 
10 <input type="text" id="code"></input>
11     <!-- <input type="button" value="显示" id="test"></input> -->    
12 <span id="xianshi"></span>
13 <form>
14 <input type="text" required="required"></input>
15 <input type="submit" value="提交"></input>
16 </form>
17 </body>
18 </html>
19 <script type="text/javascript">
20     $(document).ready(function(e){
21         
22         $("#code").blur(function(){
23             //alert($);
24             var code=$(#code).val();
25             $.ajax({
26                 url:"__SELF__",
27                 data:{code:code},
28                 type:"POST",
29                 dataType:"TEXT",
30                 success:function(data){
31                     //alert(data);
32                     $("#xianshi").html(data);
33                 }
34             })
35         })
36     });
37 </script>
View Code

 

2016/05/17 thinkphp3.2.2 ① Ajax 使用 ②前端验证

标签:

原文地址:http://www.cnblogs.com/haodayikeshu/p/5502159.html

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