• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action class being called only once in ajax

 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am new to AJAX. I am using struts1.1
I have a text box 'PerBox'. when i enter some value in the textbox, onchange event calls my ajaxfunction. I call my struts action class and in the action class i set the response which gets printed on the jsp.

My problem is that my action class is being called only once. why so?

here is my jsp page:

my action class:


The system out statement is getting printed only on first call. On consecutive calls it is not getting printed. Also, the response is being taken from cache, since even if i change the value in my action class it shows up the previous value.

Thanks.

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you setting up the page on the server NOT to cache the page? You need to set the correct headers with the response.

GET requests are meant to be cached. It makes surfing the net a lot faster.

Eric
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have four options out here,

1. Use an Ajax library that takes care of such problems - my Favorite Jquery.
2. As Eric suggested set up the page for no-cache - you'll need to look at the headers for this.
3. Use the age old trick of generating a random parameter and appending it as part of your get request.
4. Since your request is not idempotent anyways - why not make a POST request.
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:You have four options out here,

1. Use an Ajax library that takes care of such problems - my Favorite Jquery.
2. As Eric suggested set up the page for no-cache - you'll need to look at the headers for this.
3. Use the age old trick of generating a random parameter and appending it as part of your get request.
4. Since your request is not idempotent anyways - why not make a POST request.


Hey thanks a lot Sam and Eric for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic