• Post Reply Bookmark Topic Watch Topic
  • New Topic

autocomplete jquery in jsp and servlets  RSS feed

 
Abhijit Rajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jQuery for autocomplete in search bar; it works in the beginning but once the control is transferred to servlet and then redirected back to the same JSP page the jQuery autocomplete doesn't work; please guide me. PFB the code:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhijit Rajan wrote:but once the control is transferred to servlet and then redirected back to the same JSP page

I do not know what you mean by this. Please explain the flow more clearly.
 
Abhijit Rajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented a search repository where in the user can type the keywords in the searchbar and once the user clicks the search button ,all the files related to the keyword entered by the user will be retrieved from the database and displayed in one of the section of the same page. I have implemented the back end logic for retrieval in the servlet (controller) and once the data is retrieved I invoke the same jsp page from servlet and display the files name there. Now the problem starts, the jquery which used to give autosuggestion while typing in the searchbar in the beginning now longer works,incase if I need to make a new search, please guide me
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhijit Rajan wrote:once the data is retrieved I invoke the same jsp page from servlet

This is a mistake and makes no sense. The servlet -- which is invoked via Ajax by the autocompleter -- should not be returning HTML, but the JSON data for the autocomplete data. See the documentation for the autocompleter for examples.
 
Abhijit Rajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet which is invoked via Ajax by the autocompleter doesnot return HTML page that is a different servlet and it returns the JSON data and there is no problem with that. The problem starts once the servlet that is called by the form on submit, please find below the fragment of code highlighting it :


In the above code after submit when the Connector servlet is called it retrives the data from database and then redirects the control to the same jsp page, where the data is displayed below the search bar, now if I want to again make a new search then the autocomplete jquery now longer works and do not provide the suggestions , I want the solution for it.Please provide your valuable feedback.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you are saying that you go the page a second time, the autocomplete no longer works.

Have you opened the browser tools to see if the Ajax request is even being sent?
 
Abhijit Rajan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the request is not being sent ,because most probably the below line is not getting executed,


as when these jsp page is loaded from servlet the autocomplete jquery is unable to identify"#search" according to me,where search is the id of the textbox in my HTML form, as you can see in the complete code that I posted earlier
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that's actually your code, it is full of markup errors. Fix those errors.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhijit ,

Please check the documentation on how a source needs to be defined.

String: When a string is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data.
.


Please check the remote datasource example here.

Does your JSP return a JSON ?

-- Srikkanth
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!