JQ提交处理代码
- <script type="text/javascript">
- $(document).ready(function() {
- $('#title').change(function() {
- $.ajax({
- type: "GET",
- url:"check_title.php",
- dataType: "json",
- data:"title=" + $('#title').val(),
- success: function(data) {
- var str="";
- for(op1 in data){
- str += "<li><a target=blank href='/info/"+data[op1].cid+"/"+data[op1].id+".html'>"+decodeURIComponent(data[op1].title)+"</a></li>";
- }
- str2 = "<ul>"+str+"</ul>";
- $("#sampletitle").html(str2);
- }
- }); //close $.ajax(
- }); //close change(
- }); //close $(
- </script>
- //备注:decodeURIComponent 转码相当于PHP的urldecode
- //提交方式用POST处理汉字没成功,不知道为啥
HTML显示
- <div style="display:display;color:#ff0000" id="sampletitle" align="left"></div>
- <input type="text" name="title" id='title' size="40" maxlength="200" >
后台PHP处理
- <?php
- header("Cache-Control: no-cache, must-revalidate");//强制不缓存,这样每次都会重新请求
- require_once('../global.inc.php');
- $db = new dbConnect();
- $title = $_GET['title'];
- $sql = "select `id`,`cid`,`title` from `article` where `title` like '%$title%' limit 0,5";
- $result = $db->query_array($sql);
- foreach ($result as $key=>$value){
- //一定要转码哦
- $result[$key]['title'] = urlencode(iconv('gb2312','utf-8',$value['title']));
- }
- echo json_encode($result);