Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sean Michael Hayes
Ranch Hand
Posts: 54
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic