<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin:0px auto; padding:0px; } .l{ height:50px; width:198px; border-bottom:1px solid black; text-align: center; line-height:40px; vertical-align: middle; } </style> <script src="https://www.jb51.net/wenjian/jquery-2.2.3.min.js"></script> </head> <body> <div><input type="text"></div> <div> <!--<div>zhongguo</div>--> </div> </body> </html> <script> $("#name").keyup(function () { var n = $("#name").val(); if (n != ""){ $.ajax({ url:'ltchuli.php', data:{n:n}, type:'post', // dataType:'text', dataType:'json', success:function (data) { //text写法 // var s = data.split("|"); // var str = ""; // for (var i=0;i<s.length;i++) // { // str = str + "<div>" +s[i] +"</div>"; // } // $("#list").html(str); //json写法 for (var i in data){ $("#list").append("<div>" +data[i] +"</div>"); } } }); }else { $("#list").html(""); } }) </script>
处理页面
<?php /** * Created by fcc * User: Administrator * Date: 2017/10/30 * Time: 9:52 */ $n = $_POST['n']; require_once "../wenjian/DBDA.class.php"; $db = new DBDA(); $obj = "select region_name from region WHERE region_name LIKE '%{$n}%' "; $data = $db->Query($obj); //echo $data; echo json_encode($data);