Step1: develop a calling.jsp page with ajax code

<!DOCTYPE html>
<html>
<head>
<script>
var xmlhttp;
function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET","called.jsp",true);
xmlhttp.send();
}
function myFunction()
{
loadXMLDoc("a.txt",function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  });
}
</script>
</head>
<body>

<div id="myDiv"><h2>change text here</h2></div>
<button type="button" onclick="myFunction()">Change Content After button click</button>

</body>
</html>


Step2: develop a called.jsp file

called from calling jsp....<br></br>

hai...ra


 output:


After clicking the button..









0 comments:

Post a Comment