• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Trying to use AJAX to call a servlet

 
Greenhorn
Posts: 12
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am toally new to AJAX and somewhat-new to "servlets and jsp."

I am trying to send a request from an html page to a servlet on a button click. The request should update only <div id="dataDiv>, but nothing happens when i click the button. It just sits there like nothing happened.

I inserted some good'ol SOP's in the Servlet to get something on the server but it seems that the servlet isn't getting called. I am tired and lost. Please help.

I am using Mozilla 5.0, apache tomcat and jdk 6.

Code for index.html:





Code for Servlet(class DataServlet):





code for web.xml:

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to use a submit button, you need to cancel the click action.

Also your Ajax code is not going to work with older versions of IE.

Eric
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you used Firebug to look at the script errors and request activity?

 
Funkaj Kohli
Greenhorn
Posts: 12
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:If you are going to use a submit button, you need to cancel the click action.



So should I be using:

<Button type="button" onClick="UpdateData()">Click me</Button>

instead of:

<input type="submit"....>

Because I tried this and it still isn't working.

Next inserted a bunch of alert() tags in the UpdateData() function to check if its getting called alright but it seems to me that the function isn't getting invoked at all.

new code:


 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Have you used Firebug to look at the script errors and request activity?



Your URL looks suspect. You should be using a server-relative URL starting with the context path.
 
Eric Pascarello
author
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is your problem:
<script type="javascript/text">

Eric
 
Funkaj Kohli
Greenhorn
Posts: 12
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Have you used Firebug to look at the script errors and request activity?



No I haven't. Just downloaded it. I know I have an html/javascript issue but can't really see why is this function not being called?!
 
Funkaj Kohli
Greenhorn
Posts: 12
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:This is your problem:
<script type="javascript/text">

Eric



LOL!

Thanks a lot Eric! That fixed it

ps - i never thought this day would come.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic