aspose file tools*
The moose likes JSP and the fly likes Javacript portion of jsp won't run when refreshed using AJAX? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Javacript portion of jsp won Watch "Javacript portion of jsp won New topic
Author

Javacript portion of jsp won't run when refreshed using AJAX?

Sean Michael Hayes
Ranch Hand

Joined: Feb 08, 2012
Posts: 54

I have an object class that has two arraylists, a description arraylist and a values arraylist. They are related in that the numbered index in one is related to the index in the other arraylist. I.E Description[2] is for value[2].

These values are put into a servlet and passed to a jsp.

When I first load my jsp, labels are dynamically generated, with its id being a description, with the javascript function "setValue" being called and the labels innerhtml is changed to the relevant value.

The first time through it works and the value's are assigned to the correct label.
However, after AJAX refreshes the content of the page(in this case the entire body tag), the javascript in the JSLT section won't run and the innerhtml of the labels become empty. I've run some tests and it is creating the labels just not calling the javascript to populate it. Viewing the source, I can see the javascript function being called each time, with the correct value being called, the innerhtml does not change to it however.


Nikhil Padharia
Ranch Hand

Joined: Apr 19, 2012
Posts: 37
Why do you set label value explicitly by calling a script?
The script you have encoded would not get called after refreshing by an ajax call.
I would suggest you write as below as it doesn't make any difference and serves your functionality

Jagdish Hatagale
Ranch Hand

Joined: Apr 07, 2010
Posts: 33
you are sending that value with the request object and when the page get refresh the request values are reseting so make it sure that the value should be in the session object so that unless you remove it from the session it will be available with the request


Regards
Jagdish hatagale
Sean Michael Hayes
Ranch Hand

Joined: Feb 08, 2012
Posts: 54

Ah, my apologies and thank you.

I could have sworn I tried that and the innerHtml was what was written was literally "${devices.vs[dscrItems.index]}" ,must have made a mistake somewhere. Thanks a lot.
Sean Michael Hayes
Ranch Hand

Joined: Feb 08, 2012
Posts: 54

I understand that the question in this thread has been marked as resolved by me but looking back I still have a problem with this.

The first time it worked because I could simply put the JSTL segment in the labels inner html but what if I dont have that option?

I.E I want to change the values of the divs style attribute, again it works the first time with the javascript segment but as mentioned above it wont work on refresh. What can I do to keep the value every time? I tried onload but that does not work with a div.

Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Why can't you invoke the same javascript function explicity after ajax refresh is done ?
Why can't you send the response from the server which has all the required styling you need?
 
jQuery in Action, 2nd edition
 
subject: Javacript portion of jsp won't run when refreshed using AJAX?