3

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 ?

0

1 Answer 1

2

<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>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.