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>
原文地址:https://www.cnblogs.com/mayufo/p/4296359.html