XMLHttpRequest request data and Request request data writing

Simple sample code for XMLHttpRequest to send Ajax request:

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();

Simple example code of Request request:

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

Query string writing:

// URL address without parameters
".../.../getByIds"
// URL address with one parameter
".../.../getByIds?ids"+this.id
// URL address with two parameters
".../.../ getByIds?ids"+this.id+"&name="+this.name

Guess you like

Origin blog.csdn.net/YG_zhh/article/details/126946688