{"id":2027,"date":"2023-03-25T14:33:59","date_gmt":"2023-03-25T06:33:59","guid":{"rendered":""},"modified":"2023-03-25T14:33:59","modified_gmt":"2023-03-25T06:33:59","slug":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/2027.html","title":{"rendered":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22"},"content":{"rendered":"
\n
<html lang=\"en\"<\/span>>\n<head>\n <title> Example of Bootstrap Typeahead with Ajax <\/title> \n <link href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.6\/css\/bootstrap.min.css\"<\/span> rel=\"stylesheet\"<\/span>>\n <script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.js\"<\/span>><\/script>\n <script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/bootstrap-3-typeahead\/4.0.1\/bootstrap3-typeahead.min.js\"<\/span>><\/script> \n<\/head>\n<body>\n<div class=\"row\"<\/span>>\n <div class=\"col-md-12 text-center\"<\/span>>\n <br\/>\n <h1> Example of Dynamic Autocomplete search using Bootstrap Typeahead JS<\/h1> \n <input class=\"typeahead form-control\"<\/span> style=\"margin:0px auto;width:300px;\"<\/span> type=\"text\"<\/span>>\n <\/div>\n<\/div>\n<script type=\"text\/javascript\"<\/span>>\n $('input.typeahead'<\/span>).typeahead<\/span>({\n source: function (query, process) {\n return <\/span>$.get<\/span>('\/ajaxpro.php'<\/span>, { query: query }, function <\/span>(data) {\n console.log<\/span>(data);\n data = $.parseJSON<\/span>(data);\n return <\/span>process(data);\n });\n }\n });\n<\/script>\n<\/body>\n<\/html><\/pre>\n<\/code>\n <\/div>\n
\n \u73b0\u5728\u6211\u4eec\u7684\u793a\u4f8b\u9700\u8981 JSON \u6570\u636e\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u65b0\u9875\u9762\u5e76\u6839\u636eAjax\u8bf7\u6c42\u83b7\u5f97\u6b64\u529f\u80fd\u3002\u56e0\u6b64\uff0c\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u518d\u521b\u5efa\u4e00\u9875ajaxpro.php\u6587\u4ef6\u3002\u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801:\n <\/div>\n\n ajaxpro.php:\n <\/div>\n\n<?php\n \n define (DB_USER, \"root\"<\/span><\/span>);\n define (DB_PASSWORD, \"root\");\n define (DB_DATABASE, \"learn\"<\/span>);\n define (DB_HOST, \"localhost\"<\/span>);\n $mysqli = new <\/span>mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);\n $sql = \"SELECT items.title FROM items \n WHERE title LIKE '%\"<\/span>.$_GET['query'<\/span>].\"%'<\/span>\n LIMIT 10\"; \n $result = $mysqli->query($sql);\n \n s$json = [];\n while($row = $result->fetch_assoc()){\n $json[] = $row['title'<\/span>];\n }\n echo json_encode($json);<\/pre>\n<\/code>\n <\/div>\n
\n \u6211\u4eec\u7684\u4ee5\u4e0a\u4ee3\u7801\u5df2\u51c6\u5907\u5c31\u7eea\uff0c\u53ef\u4ee5\u8fd0\u884c\u3002\u8fd0\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u5c06\u83b7\u5f97\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n
<\/p>\n
\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-2027","post","type-post","status-publish","format-standard","hentry","category-bootstrapjc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2027"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=2027"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2027\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=2027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=2027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=2027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}