标签:function ons ajax bsp tle oct end script 返回
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-ajax</title>
<script>
/*
ajax : Asynchronous JavaScript and XML 异步JavaScript和XML
用javascript异步形式去操作xml
数据交互
*/
window.onload = function(){
var oBtn = document.getElementById(‘btn‘);
oBtn.onclick = function(){
//打开浏览器
var xhr = new XMLHttpRequest();
//在地址栏输入地址
xhr.open(‘get‘,‘1.txt‘,true);
//提交
xhr.send();
//等待服务器返回内容
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
}
}
}
</script>
</head>
<body>
<input type="button" value="按钮" id="btn"/>
</body>
</html>
------------------------------------------------------------
1.txt
Hello world!
标签:function ons ajax bsp tle oct end script 返回
原文地址:http://www.cnblogs.com/shbkbj/p/6853134.html