Ajax Simple Demo
Ajax Simple Demo
<%@ 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 'ajax2.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> var xmlHttpRequest = null; function ajaxSubmit(){ if(window.ActiveXObject){ xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }else{ xmlHttpRequest = new XMLHttpRequest(); } if(null != xmlHttpRequest){ var v1 = document.getElementById("v1").value; var v2 = document.getElementById("v2").value; //xmlHttpRequest.open("GET","servlet/AjaxServlet2?v1=" + v1 + "&v2=" + v2,true); xmlHttpRequest.open("POST","servlet/AjaxServlet2",true); xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlHttpRequest.onreadystatechange = ajaxCallback; xmlHttpRequest.send("v1=" + v1 + "&v2=" + v2); } } function ajaxCallback(){ if(xmlHttpRequest.readyState == 4){ if(xmlHttpRequest.status == 200){ var responseText = xmlHttpRequest.responseText; alert(responseText); document.getElementById("div1").innerHTML=responseText; } } } </script> </head> <body> <input type="text" name="value1" id="v1"><br> <input type="text" name="value2" id="v2"><br> <input type="button" value="get text" onclick="ajaxSubmit();"><br> <form action="" enctype="application/x-www-form-urlencoded"></form> <div id="div1"></div> </body> </html>
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05