Ajax異步刷新 提交數據

<html>
	<head>
	    <meta charset="UTF-8">
	    <title></title>
		<script>
	            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");
	                }
	                xmlhttp.onreadystatechange=function(){//每當 readyState 改變時,就會觸發 onreadystatechange 事件。
	                    if (xmlhttp.readyState==4 && xmlhttp.status==200){
	                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	                    }  
	                }          
	                xmlhttp.open("POST","test1.jsp",true);
					xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					xmlhttp.send("fname=Bill&lname=Gates");
	            }
	        </script>
	</head>
	<body>
		<div id="myDiv">cd</div>
		<button onclick="loadXMLDoc()">change</button>
	</body>
</html>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%
	String fname = request.getParameter("fname");
	String lname = request.getParameter("lname");
	%>
nihao,<%=fname%> <%=lname%>
</body>
</html>
相關文章
相關標籤/搜索