var suggest = new bsn.AutoSuggest('search_input', {
script:"search.php?",
varname:"q",
json:true,
shownoresults:false,
maxresults:5
});
var suggest = new bsn.AutoSuggest('search_input', {
script:"search.php?",
varname:"q",
json:true,
shownoresults:false,
maxresults:5
});
As you can see from the settings - we bind auto-fill to the search_input field, and the search.php script performs the entire search procedure. It can produce results both in JSON and in XML format, but since there is no need for universal output (id, value, info are stitched in js), JSON can be generated simply as strings without fully transforming php objects into JSON. Search result in JSON format:<code> {results: [<br /> {id: "1", value: "Foobar", info: "Cheshire"}, <br /> {id: "2", value: "Foobarfly", info: "Shropshire"}, <br /> {id: "3", value: "Foobarnacle", info: "Essex"} <br />]} </ code>Do not forget to limit the size of the word to at least 3 letters. The script itself will generate a div and set it under the field, and then you can press the keys to select the appropriate result.
Source: https://habr.com/ru/post/13626/
All Articles