JSP Ajax

html代码:
<!DOCTYPE html>
<html>
  <script>
  function display()
  {
   var div=document.getElementById("my");
   if(div.innerHTML!="")
   {
   div.innerHTML="";
   return;
   }
   var xmlHttp=new XMLHttpRequest();
   xmlHttp.open("GET","introduce.jsp",true);
   xmlHttp.onreadystatechange=function()
   {
   if(xmlHttp.readyState==4 && xmlHttp.status == 200)
   {div.innnerHTML=xmlHttp.responseText;
   }
   }xmlHttp.send();
  }
  </script>
  <body>
    <div id="my" style="background-color:yellow;widht:300px;height:400px"></div>
    <input type="button" onclick="display()" value="hehe">
  </body>
</html>


jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<html>
<body>
out.print("this is a demo");
</body>
</html>
原文地址:https://www.cnblogs.com/webglcn/p/3527411.html