SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: AJAX and JSP
-
Jun 3, 2008, 19:41 #1
- Join Date
- Sep 2004
- Location
- USA
- Posts
- 161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
AJAX and JSP
Hi All,
I have a jsp which displays a list read from database. In database, status field is dynamically updated by background thread. I want to display the changed status without refreshing page. So, I am using AJAX. I want to make AJAX request conditionally. I mean if all the statuses on the page are complete, then I don't want to make AJAX call, because there is nothing to update. I want to make AJAX call only if I have status other than complete. From my servlet, I set a flag in a request attribute as true or false dependng on status. In a JSP I get request attribute assign it a js variable. If it's true make AJAX call and I call that function on body onload. It works fine for the first time. But js variable never gets updated even though sevlet updates flag value. How do I address this issue? Calling function on onload will not work.
Any help is appreciated.
Thanks,
-
Jun 4, 2008, 09:57 #2
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Lets see the javascript generated by your JSP then
-
Jun 4, 2008, 19:14 #3
- Join Date
- Sep 2004
- Location
- USA
- Posts
- 161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:function autoUpload() { var flag = <%= request.getAttribute("istrue") %> if (flag == "true") { new Ajax.PeriodicalUpdater('top', 'DisplayList.do', {method:'post',frequency:60,decay:2}); } }
-
Jun 5, 2008, 08:31 #4
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if (flag == "true")
This is looking for the value of flag to be a string - "true". But you're probably creating a boolean using
var flag = <%= request.getAttribute("istrue") %>
(unless the jsp is adding quotes)
Try:
if (flag) {
instead
-
Jun 5, 2008, 09:55 #5
- Join Date
- Sep 2004
- Location
- USA
- Posts
- 161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah. Now, I changed it to null. I mean I'm setting attribute value only if condition is true otherwise it's null. In js my condition looks like this -
if (flag != null)
But, didn't work
-
Jun 5, 2008, 10:07 #6
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try putting an alert inside the condition, just to see if it's working.
-
Jun 5, 2008, 13:32 #7
- Join Date
- Sep 2004
- Location
- USA
- Posts
- 161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It doesn't.
Bookmarks