①Ajax使用: 注意传值的所有过程用的是小写,及时数据库列的名称中有大写字母
控制器部分:
AjaxController.class.php
<?php namespace HomeController; use ThinkController; class AjaxController extends Controller { public function Ajax(){ if (empty($_POST)) { $this->display(); } else{ $code=$_POST["code"]; $nation=D('nation'); $attr=$nation->find($code); $name=$attr["name"]; $this->ajaxReturn($name,'eval'); } } }
②Ajax.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="../../../../../jquery-1.11.2.min.js"></script> </head> <body> <input type="text" id="code"></input> <!-- <input type="button" value="显示" id="test"></input> --> <span id="xianshi"></span> <form> <input type="text" required="required"></input> <input type="submit" value="提交"></input> </form> </body> </html> <script type="text/javascript"> $(document).ready(function(e){ $("#code").blur(function(){ //alert($); var code=$('#code').val(); $.ajax({ url:"__SELF__", data:{code:code}, type:"POST", dataType:"TEXT", success:function(data){ //alert(data); $("#xianshi").html(data); } }) }) }); </script>