标签:文本 oop upload opera width 方法 adt let ogre
<button id="btn">请求纯文本</button>
<script>
let btn = document.getElementById(‘btn‘);
btn.addEventListener("click",loadText);
function loadText(){
let xhr = new XMLHttpRequest();
xhr.open(‘GET‘,‘sample.txt‘,true);
xhr.onreadystatechange = function(){
console.log("READYSTATE"+ xhr.readyState);
console.log(this.responseText);
}
xhr.send();
}
</script>
function loadText(){
let xhr = new XMLHttpRequest();
xhr.open(‘GET‘,‘sample.txt‘,true);
console.log("READYSTATE"+ xhr.readyState);
xhr.onreadystatechange = function(){
console.log("READYSTATE"+ xhr.readyState);
if(this.status == 200 && this.readyState == 4){
console.log(this.responseText);
}else if(this.status == 404){
console.log("网页不存在");
}
}
xhr.send();
}
function loadText(){
let xhr = new XMLHttpRequest();
xhr.open(‘GET‘,‘sample.txt‘,true);
console.log("READYSTATE"+ xhr.readyState);
//两种请求方式onload和onreadystatechange
xhr.onload = function(){
console.log("READYSTATE"+ xhr.readyState);
console.log(this.responseText);
}
xhr.send();
}
function loadText(){
let xhr = new XMLHttpRequest();
xhr.open(‘GET‘,‘sample.txt‘,true);
console.log("READYSTATE"+ xhr.readyState);
//两种请求方式onload和onreadystatechange
xhr.onprogress = function(){
console.log("测试加载状态READYSTATE"+ xhr.readyState);
}
xhr.onload = function(){
console.log("READYSTATE"+ xhr.readyState);
console.log(this.responseText);
}
xhr.send();
}
xhr.onload = function(){
document.getElementById(‘text‘).innerHTML = this.responseText;
}
Ajax 两种请求方式的区别onload和onreadystatechange
标签:文本 oop upload opera width 方法 adt let ogre
原文地址:https://www.cnblogs.com/ygunoil/p/12565543.html