使用AJAX时发现修改的页面没有得到改变

来源:互联网 发布:袁咏仪长相知乎 编辑:程序博客网 时间:2024/05/16 14:07

  使用AJAX发现当我们修改了xmlhttp.open("GET","Destination.jsp",true);中的Destination.jsp页面内容时需要先把修改的页面单独运行一次这样才能当前页面通过xmlhttp.open("GET","Destination.jsp",true)显示Destination.jsp内容时呈现的是修改后的内容页面。

  

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><script type="text/javascript">function loadXMLDoc(){var xmlhttp;if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }  //未初始化状态对象已经创建,尚未调用open()输出0  alert(xmlhttp.readyState)  xmlhttp.onreadystatechange=function()  {  if (xmlhttp.readyState==4 && xmlhttp.status==200)    {    document.getElementById("myDiv").innerText=xmlhttp.responseText;    }  } xmlhttp.open("GET","Destination.jsp",true);//已初始化状态,调用open()方法以后输出1alert(xmlhttp.readyState)xmlhttp.send();}</script></head><body><h2>AJAX</h2><button type="button" onclick="loadXMLDoc()">请求数据</button><div id="myDiv"></div></body></html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'Destination.jsp' starting page</title>      </head>  <body>               欢迎你啊fds3214     <input type="button" value="提交"/>     <table>     <tr>     <td></td>     </tr>     </table>  </body></html>

0 0
原创粉丝点击