• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Javascript issue when loading the JSP page content via an AJAX call

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting an issue when loading the JSP page content via an AJAX call. What i am doing is loading the same page via AJAX call and the java script function values are dynamic values taking from the session.

The problem is that it’s not executing the latest java script that comes in the Ajax page content.

Could someone give an idea?

Appreciate a response.

A sample code is given below.

Regards,
Dinusha00

----------------------my JSP page--------------
<html>

<div id="mypage">
<script>
function addmyselection{
/*
sending an ajax call to the same page and taking the content to ajaxpagecontent variable
*/
document.getElementById("mypage").innerHTML=ajaxpagecontent;
}

function updatelatestvalues(){
document.getElementById("amount").value="<%=sessionamount%>"
}
</script>

<input type="hidden" id="amount" name="amount"/>
<input type="button" id="add" name="add" onclick="addmyselection();"/>
/*
Normal body content
*/

<script>
updatelatestvalues();
</script>

</div>
</html>
--------------------------------
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript is not evaluated when you make place it in the page with innerHTML. You need to manually evaluate it yourself. If you were using a library such as JQuery or Prototpye.js, they would do it for you.

Eric
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is madness at this point to do Ajax "by hand". As Eric pointed out, jQuery, or any of the other Ajax-enabled libraries, take care of lots of little nuances (such as script evaluation) that are a pain in the rear to take care of yourself.
 
dinusha ambagahawita
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the responses.

Dinusha.
 
    Bookmark Topic Watch Topic
  • New Topic