Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: doSearch is not defined

getting javascript error like

Uncaught ReferenceError: doSearch is not defined

Here am attaching code, its spring mvc the controller code is

@RequestMapping("/ajaxSearch")
public @ResponseBody List<Book> performLooseSearch(@RequestParam("CHARS") String chars)
{       
    System.out.println("CHARS: "+chars);
    return bookService.searchBooksByLooseMatch(chars);
}

and jsp and java script here

<html>

<head>
    <title>Loose Search</title>
    <script type="text/javascript" src="/BookShopping/resources/jquery-1.4.2.min.js" />

    <script type="text/javascript">
        function doSearch() {
            // make request to server...
            alert("#searchBox  " + $('#searchBox').val());

            $.getJSON("ajaxSearch.do", {
                CHARS: $('#searchBox').val()
            }, function(data) {
                // the call back
                alert("Response received " + data);
            });
        }
    </script>
</head>

<body>
    <h1>Loose Search</h1>
    <input type="text" onKeyUp="doSearch();" id="searchBox" />

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

</html>

Any suggestion ?

like image 300
Mahesha M Avatar asked Nov 27 '25 21:11

Mahesha M


1 Answers

<script> cannot be self closed. Check Why don't self-closing script tags work?

Change

<script type="text/javascript" src="/BookShopping/resources/jquery-1.4.2.min.js"/>

to

<script type="text/javascript" src="/BookShopping/resources/jquery-1.4.2.min.js"></script>
like image 189
Tushar Avatar answered Nov 29 '25 10:11

Tushar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!