ajax 第一个程序

时间:2023-03-08 16:23:18
ajax  第一个程序
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
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" id="btn" value="提交">
</body>
</html>