• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for the responses.

Dinusha.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic