Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
184
rated 0 times [  190] [ 6]  / answers: 1 / hits: 15082  / 14 Years ago, sun, january 9, 2011, 12:00:00

i am creating a web project using JSP, and is trying to implement a simple search for users from my database using jquery autocomplete, however i am having trouble understanding how it works. i have little to no knowledge on jquery and ajax just to let you know. i have done the following code and am stuck.



<%@page contentType=text/html pageEncoding=UTF-8 import=ewa.dbConnect,ewa.sendEmail,ewa.pwGen,ewa.hashPw,java.sql.* %>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
http://www.w3.org/TR/html4/loose.dtd>

<html>
<head>
<link rel=stylesheet type=text/css href=css/jquery.autocomplete.css />
<script src=js/jquery.autocomplete.js></script>
<script type=text/javascript
src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js></script>
<meta http-equiv=Content-Type content=text/html; charset=UTF-8>
<title>JSP Page</title>
</head>
<body>
<input type=text id=search name=search/>
<script>
$(#search).autocomplete(getdata.jsp);
</script>
</body>
</html>


getdata.jsp



<%@page contentType=text/html pageEncoding=UTF-8 import=ewa.dbConnect,java.sql.* %>
<%! dbConnect db = new dbConnect(); %>
<%
String query = request.getParameter(q);
db.connect();
Statement stmt = db.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(SELECT username FROM created_accounts WHERE username LIKE +query);
while(rs.next())
{
out.println(rs.getString(username));
}
db.disconnect
%>


if i am not wrong i read from a website, the parameter q is default and is just there, however how do i display the data? how do i pass the values from getdata.jsp into the autocomplete?


More From » java

 Answers
16

You're calling the autocomplete script tag before jQuery has been included. So, not having jQuery to latch onto (as the jQuery object hasn't been defined), nothing from the jQuery autocomplete plugin will load.



You have



 <script src=js/jquery.autocomplete.js></script>
<script type=text/javascript
src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js></script>


It should be



    <script type=text/javascript
src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js></script>
<script src=js/jquery.autocomplete.js></script>


Reverse the order, and the Firebug errors you mentioned should disappear; I'm not sure it'll solve everything, but nothing will work until that's resolved.


[#94312] Friday, January 7, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gabriel

Total Points: 323
Total Questions: 107
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
;