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


    显示效果:

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

    控制器部分:

    AjaxController.class.php

     1 <?php 
     2 namespace HomeController;
     3 use ThinkController;
     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
  • 相关阅读:
    12月11日
    081212 晴
    12月10日
    树莓派项目——基于树莓派的WIFI网络互传系统设计
    IDE
    边缘检测
    Android Launcher桌面应用快捷方式的开发
    android ui事件处理分析
    listview 分析
    ApplicationsIntentReceiver.class
  • 原文地址:https://www.cnblogs.com/haodayikeshu/p/5502159.html
Copyright © 2020-2023  润新知