试图在输入框中实施实时搜索 [英] trying to implement live search in a input box

查看:57
本文介绍了试图在输入框中实施实时搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在文本框中实施实时搜索,该选项列表来自服务器,如果该项目不可用,则应动态添加,例如如果我键入"gre"并选择它,则应将其添加到该列表,或者它应该显示在列表顶部

i'm trying to implement live search in a textbox, the list of options coming from the server, if the item is not available it should add dynamically, like if i type "gre" and selects that, it should added to the list or it should show in the top of the lists

Codeply: https://www.codeply.com/go/d6WaXok32m

Codeply : https://www.codeply.com/go/d6WaXok32m

如代码中所指定,元素"entranceExamSearch"输入框包含项目列表

as specified in the code, the element 'entranceExamSearch' input box contails list of items

推荐答案

此代码将带给您一些想法.

This code will give you some idea.

HTML:

<input type="text" id="searchPro" />
Your all the dynamic result will be show inside the div
<div id="searchLog"></div>

JQuery:

$("#searchPro").autocomplete({
    source: function(request,response) {
        $.ajax({
            url: "php.func.php",
            type: "POST",
            data: { term: request.term },
            success: function (searchData) {
                $('#searchLog').html(searchData);
            }
        })
    }
});

PHP:php.func.php

$find = "SELECT * 
        FROM tbl_products
        WHERE (`product_name` LIKE '%".$_REQUEST['term']."%')";

$resset = $conn->query($find);
    while ($res = mysqli_fetch_object($resset)) {
    $findRes[] = $res;
}
if (!empty($findRes)) {
    foreach ($findRes as $ResultSet) {
        echo "<tr><td>".$ResultSet->product_name."</td>";
    }
}else{
    echo "<p>No Result Found for keyword <b>".$_REQUEST['term']."</b>..<p><hr/>";
}

这里是链接:[JQuery自动完成] [1]

Here is the link: [JQuery Autocomplete][1]

这是我在项目中使用的基本参考代码.您可以根据需要进行修改.希望这会帮助你. 有关更多 https://jqueryui.com/autocomplete/

This is for your basic reference code i have use in my project. you can modify as per your need. Hope this will help you. For more https://jqueryui.com/autocomplete/

这篇关于试图在输入框中实施实时搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆