码迷,mamicode.com
首页 > Web开发 > 详细

原生ajax

时间:2016-05-10 09:40:39      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax</title>
</head>
<body>
<button id="requestBtn">请求文本</button>
<div id="txt"></div>
<script type="text/javascript">
var requestBtn = document.getElementById("requestBtn");
var txt = document.getElementById("txt");
var http = new XMLHttpRequest();
var url = "b.txt";
requestBtn.onclick = function() {
http.open("get", url, true);
http.send(null);
http.onreadystatechange = function() {
if(http.readyState == 4 && (http.status == 200 || http.status == 304)) {
console.log(http.responseText);
txt.innerHTML = http.responseText;
}
}
}
</script>
</body>
</html>

原生ajax

标签:

原文地址:http://www.cnblogs.com/fengzj/p/5476511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!