I have a JSP page called DEMO1.jsp where I've implemented AJAX code to refresh every minute. In DEMO1.JSP, the code snippet looks like this:
<head>
<script type='text/javascript'>
setInterval(function(){
document.getElementById('bgframe').contentWindow.myInternalFunction();
}, 5*1000);
</script>
</head>
<body onload="AutoRefreshValid();" style="margin:1px;font-family: Serif, Arial, Times, serif;" id="ValidWaybills"><center>
<iframe id='bgframe' style='display:none;' src='DEMO2.jsp'></iframe>
<script type="text/javascript">
function AutoRefreshValid(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("No AJAX");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('ValidWaybills1Valid').innerHTML=xmlHttp.responseText;
setTimeout('AutoRefreshValid()',5*1000);
}
}
xmlHttp.open("GET","DEMO2.jsp",true);
xmlHttp.send(null);
}
</script>
<div id="ValidWaybills1Valid">
</div>
In DEMO2.JSP, I've written JavaScript code that needs to run using AJAX in DEMO1.jsp without reloading the page every 5 seconds. Here is the code from DEMO2.jsp:
<head>
<script type="text/javascript">
function callme3(){
<% Date d1 = new Date();
%>
alert("Date is <%=d1%>");
}
</script>
</head>
<body onload="callme3()">
</div>
Thank you and regards, Sudarshan