XMLHttpRequest请求数据与Request请求数据写法

XMLHttpRequest发送Ajax请求的简单示例代码:

let xhr;
if (window.XMLHttpRequest) {
    
    
   xhr = new XMLHttpRequest();
} else {
    
    
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.responseType = "arraybuffer"; 
xhr.open("GET", " /getByIds?ids="+ this.rgbImagePath, true);
xhr.onload = function () {
    
    
    if (xhr.readyState == 4 && xhr.status == 200) {
    
    
       //xhr.response为请求到的数据
       console.log('xhr.response:',xhr.response);
     }
 };
xhr.send();

Request请求的简单实例代码:

request({
    
    
    url:"/getByIds?ids="+this.rgbImagePath,
    methods:"get",
   }).then((res)=>{
    
    
     this.imageArray = res;
   })

查询字符串写法:

//不带参数的URL地址
“…/…/getByIds”
//带一个参数的URL地址
“…/…/getByIds?ids”+this.id
//带两个参数的URL地址
“…/…/getByIds?ids”+this.id+“&name=”+this.name

猜你喜欢

转载自blog.csdn.net/YG_zhh/article/details/126946688