使用XMLHttpRequest实现AJAx
2016-11-13 19:30
543 查看
<%@ 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 'index1.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">
<script type="text/javascript">
window.onload=function(){
//获取节点,为其添加onclick响应函数
document.getElementsByTagName("a")[0].onclick=function()
{
//3:创建一个XMLHttpRequest对象
var xmlHttp=new XMLHttpRequest();
//4:准备发送请求的数据:url,设置时间戳,禁用缓存
var url=this.href+"?time="+new Date();
var method="GET";
//5:调用XMLHttpRequest对象的open方法
xmlHttp.open(method,url);
//6:调用XMLHttpRequest对象的send方法
xmlHttp.send(null);
//7:为XMLHttpRequest对象添加onreadystatechange响应函数
xmlHttp.onreadystatechange=function(){
//8:判断响应是否完成:XMLHttpRequest对象的onreadystate属性值是否是4的时候
if(xmlHttp.readyState==4)
{
//9再判断响应属性值是否为200
if(xmlHttp.status==200||xmlHttp.status==304)
//10: 打印响应的结果
alert(xmlHttp.responseText);
}
}
//2:取消节点的默认行为
return false;
}
}
</script>
</head>
<body>
<a href="day1/helloAjax.txt">HelloAjax</a>
</body>
</html>
<%
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 'index1.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">
<script type="text/javascript">
window.onload=function(){
//获取节点,为其添加onclick响应函数
document.getElementsByTagName("a")[0].onclick=function()
{
//3:创建一个XMLHttpRequest对象
var xmlHttp=new XMLHttpRequest();
//4:准备发送请求的数据:url,设置时间戳,禁用缓存
var url=this.href+"?time="+new Date();
var method="GET";
//5:调用XMLHttpRequest对象的open方法
xmlHttp.open(method,url);
//6:调用XMLHttpRequest对象的send方法
xmlHttp.send(null);
//7:为XMLHttpRequest对象添加onreadystatechange响应函数
xmlHttp.onreadystatechange=function(){
//8:判断响应是否完成:XMLHttpRequest对象的onreadystate属性值是否是4的时候
if(xmlHttp.readyState==4)
{
//9再判断响应属性值是否为200
if(xmlHttp.status==200||xmlHttp.status==304)
//10: 打印响应的结果
alert(xmlHttp.responseText);
}
}
//2:取消节点的默认行为
return false;
}
}
</script>
</head>
<body>
<a href="day1/helloAjax.txt">HelloAjax</a>
</body>
</html>
相关文章推荐
- 使用XMLHttpRequest实现AJAX
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- Ajax-05 使用XMLHttpRequest和jQuery实现Ajax实例
- 10002---使用 XMLHttpRequest 实现 Ajax
- 习惯了使用jQuery的ajax方法,看看原生js使用xmlhttpRequest实现ajax请求
- 不使用XMLHttpRequest对象实现Ajax效果
- 使用 XMLHttpRequest 实现 Ajax 三:取回 Json 数据
- 使用 XMLHttpRequest 实现 Ajax 四:调用 Webservice
- struts2中Ajax的操作实现及其核心对象XMLHttpRequest对象的使用
- 使用XmlHttpRequest实现简单Ajax
- [学习小结]Ajax_使用 XMLHttpRequest 实现 Ajax
- 使用XMLHttpRequest 实现ajax效果
- 使用xmlHttpRequest实现Ajax技术
- 使用 XMLHttpRequest 实现 Ajax
- 如何使用XmlHttpRequest对象实现ajax?
- XMLHttpRequest Level 2 使用指南——ajax实现http(s)协议的原理
- 使用XMLHTTPRequest和JQuery库实现AJax
- 使用XmlHttpRequest实现简单Ajax
- 使用XMLHttpRequest 实现ajax效果
- 使用 XMLHttpRequest 实现 Ajax 二:取回 XML 数据