使用原始的javascript实现ajax

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript"> function run() { var xmlHttpReq = null;
if (window.ActiveXObject) {
//IE5,IE6是以ActiveXObject的方式引入XMLHttpRequest对象的
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
//除IE5和IE6以外的浏览器
//XMLHttpRequest是window的子对象
实例化一个XMLHttpRequest对象
xmlHttpReq = new XMLHttpRequest();
} xmlHttpReq.open("get", "Handler1.ashx", true); //一旦readyState值改变,将会调用该函数
xmlHttpReq.onreadystatechange = function () { //设置回调函数
if (xmlHttpReq.readyState==4) {
if(xmlHttpReq.status==200){
alert(xmlHttpReq.responseText);
document.getElementById('h3').innerHTML = xmlHttpReq.responseText; }
}
} //因为使用get方法提交,这里可以使用null作为参数调用。
xmlHttpReq.send(null);//在IE11下不用写null也调用成功了。
}
</script>
</head>
<body>
<input type="button" value="ajax提交" onclick="run();" />
<h3 id="h3"></h3>
</body>
</html>

最新文章

  1. head标签详细讲解
  2. 注解:【基于主键的】Hibernate1-&gt;1关联
  3. Bash之PS1配置
  4. tp框架总结(二)
  5. caffe在windows 下的配置及matlab接口编译(无GPU)
  6. jQuery学习笔记(一):入门【转】
  7. 正在执行的SQL和之前执行的SQL
  8. UVA 847 - A Multiplication Game(游戏)
  9. 【Linux】Vim编辑器-批量注释与反注释
  10. buttongroup中content一次性加载的解决方法
  11. FileZilla出现Failed to convert command to 8 bit charset 
  12. 【python】正则替换
  13. String str.trim()
  14. 074 hbase与mapreduce集成
  15. VMware 获取该虚拟机的所有权失败
  16. 个人犯的一个golang routine错误
  17. CTF密码学之摩斯密码
  18. Treasures and Vikings(两次搜索)
  19. .net程序中http请求的超时配置
  20. Jmeter分布式测试的各种坑之jmeter-server修改ip

热门文章

  1. Android 开发之避免被第三方使用代理抓包
  2. 【COGS2622】后缀平衡树
  3. 【LOJbeta round1】ZQC的手办
  4. 图论-最近公共祖先-离线Tarjan算法
  5. Linux平台用C++实现事件对象,同步线程(转)
  6. CSS3新属性解释及用法
  7. JWT认证不通过导致不能访问视图的解决方案
  8. (转载)IntelliJ IDEA 自动导入包 快捷方式
  9. [转]6个HelloWorld
  10. 2017 Hackatari Codeathon B. 2Trees(深搜)(想法)