javascript ajax请求

时间:2023-12-27 22:08:49
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" /> </head>
<body>
<input id="btn1" type="button" value="提交" />
<script type="text/javascript">
var oBtn = document.getElementById("btn1");
oBtn.onclick = function () {
var oAjax = null;
if (window.XMLHttpRequest) {
oAjax = new XMLHttpRequest();
} else {
oAjax = new ActiveXObject("");
}
oAjax.open("get", "aaa.txt", true);
oAjax.send();
oAjax.onreadystatechange = function () {
if (oAjax.readyState == 4) {
if (oAjax.status == 200) {
alert(oAjax.responseText);
}
}
};
};
</script>
</body>
</html>