Html 代码:

<html>
<body> <div id="myDiv"><h3>Let AJAX change this text</h3></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button> </body>
</html>

js代码:

<script type="text/javascript">

    var xmlhttp;
function loadXMLDoc() {
//ajax script goes here...
if(window.XMLHttpRequest) {
//code for IE7+, firefox, Chrome, Opera,Sarari
xmlhttp = new XMLHttpRequest();
}else {
//code for IE6,IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} if(xmlhttp != null) { //创建响应XMLHttpRequest对象状态变化的函数
xmlhttp.onreadystatechange = httpStateChange;
//创建http请求
xmlhttp.open('GET', 'json/data.json', true);
//发送http请求
xmlhttp.send(null); } } function httpStateChange() { console.log(xmlhttp.readyState, xmlhttp.status);
//请求中.
if(xmlhttp.readyState == 1) {
//loading..
document.getElementById('myDiv').innerHTML = 'loading..';
} ////异步调用完毕
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var data = JSON.parse(xmlhttp.responseText);
console.log(data);
document.getElementById('myDiv').innerHTML = data.sites[1].Name;
}
} </script>

最新文章

  1. PHP设计模式(八)桥接模式(Bridge For PHP)
  2. curl模拟自动登陆&amp;采集网页数据
  3. Storm与Spark:谁才是我们的实时处理利器
  4. 那些臭名昭著的sql
  5. Linux常用性能检测命令解释
  6. C语言编写的随机产生四则运算测试题
  7. &lt;a&gt;多颜色标签点击之后保持原色的一次实践, Ext Panel下解决及通用方案思路
  8. 浏览器检测(BrowserDetect.js)
  9. Qt使用快捷键
  10. String,StringBuffer以及StringBuilder的差别
  11. go pkg
  12. 【LeetCode】87. Scramble String
  13. Python IDLE快捷键一览
  14. NOIP2012疫情控制(二分答案+倍增+贪心)
  15. LeetCode 63. Unique Path II(所有不同路径之二)
  16. Elasticsearch过滤器——filter
  17. g++基本用法
  18. 遇到ANR问题的处理步骤
  19. ArcGIS 常见错误
  20. Ubuntu postgres 内网 安装 卸载

热门文章

  1. 关于几类STL容器swap的复杂度问题
  2. [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
  3. Visual Studio 调试系列10 附加到正在运行的进程
  4. 动手学深度学习5-softmax回归
  5. PostMan测试REST接口时候,如何绕过登录的验证
  6. POJ 1306 暴力求组合数
  7. Redmine添加插件
  8. https的原理入门
  9. Mybatis系列(一)— 处理冲突字符
  10. [转] JS中arr.forEach()如何跳出循环