0

I try to create a live search using php mysql ajax

Input field

<input type="text" onkeyup="getProducts(this.value)" class="form-control">

Display result of search

 <div id="results"></div>

Ajax googleapis connection

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

Fuction getProducts

 <script type="text/javascript">
        function getProducts(value) {
            $.post("getProducts.php", {
                    partialState: value
                }, function(data) $("#results").html(data);
            });

        }

    </script>

getProducts.php code page

include("includes/connect.php");

$partialStates=$_POST['partialState'];

$states=mysqli_query($conn,"
        select 
        p.db_pcode,
        p.db_pname,
        p.db_punit,
        p.db_pprice,
        p.db_pqtyalert,
        p.db_pcategory,
        p.db_psupplier,
        p.db_pdesc,
        p.db_pvat,
        p.db_pdate,
        p.db_corid,
        c.db_ccat as categoryname,
        su.db_sname as suppliername,
        s.db_secname as blockname,
        s1.db_secid as cornerid,
        s1.db_secname as cornername,
        s2.db_secid as sectionid,
        s2.db_secname as sectionname
        from tbl_products as p
        left join tbl_category as c
        on 
        c.db_cid=p.db_pcategory
        left join tbl_suppliers as su
        on
        su.db_sid=p.db_psupplier
        left join tbl_section as s
        on
        s.db_secid=p.db_corid
        join tbl_section as s1
        on 
        s.db_parent=s1.db_secid 
        join tbl_section as s2
        on
        s1.db_parent=s2.db_secid 
        where 
        p.db_pname like '%$partialStates%'
        ")or die(mysqli_error($conn));
while($state=mysqli_fetch_array($states)){
    echo"<div>".$state['db_pname']."</div>";
}

The Problem is that the code don't display any thing

i try to open the getProducts.php page to see if i have any php error

but no error appear and the products are print

Can any one help to know where is the mistake ?? in the console i have this 2 errors

Uncaught SyntaxError: Unexpected identifier

2products.php:124 Uncaught ReferenceError: getProducts is not defined

6

1 Answer 1

2

You have a syntax error ... missing a { in $.post callback

$.post("getProducts.php", {partialState: value}, function(data) { 
                                                            // ^^ missing
   $("#results").html(data);
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.