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 ?

Tushar
  • 85,780
  • 21
  • 159
  • 179
Mahesha M
  • 135
  • 13

1 Answers1

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>
Community
  • 1
  • 1
Tushar
  • 85,780
  • 21
  • 159
  • 179