• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX+STRUTS

 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Above is the javascript function which gets called on body load first up and automatically then onwards with set timer

The problem i am facing is when first up the body gets loaded the action for ../cm.do gets called but not after

What could be the reason for this?

Is there any other way?

I think Merril you can help in this regard, as you allready have solved my related problem...

Thanks in Advance
Manoj Amrutkar
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaScript setTimeout method executes code only once after the specified interval. If you want the code to execute every 5 seconds, you need to use the setInterval() method.

Also, I'd suggest making req a global variable, and splitting the above function into two functions: one to initialize req, and another to send the message. Only the function to send the message should be put in the setInterval loop.
 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have called that setTimeout function in calling function(second last line of the code) so basically it's unconditional loop.
That is not the problem also i have tried alert and it fires message after some time interval.
but there is something else which is giving problem i do have some other code of javascript function is it might be creating problem?



addMessages function is called on some onclick of button.


Thanks in advance
Manoj Amrutkar
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I see what you mean about the recursive call. You might try increasing the time interval. It could be that the request isn't able to complete in the time allotted.

Also, try my earlier suggestion about only initializing the request once, and then doing the "send" part in a loop.
 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill,
Well i got stuck man why this action is not been called after some time interval?
Please try out following code.....

//NewAction.java


Thanks
Manoj
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of an action called with through AJAX, I'd recommend you format the response directly using the HttpServletResponse object's PrintWriter and then retun null from the execute() method.

See the example toward the end of this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic