📜  ajax - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:26.150000             🧑  作者: Mango

代码示例4
var xhr = new XMLHttpRequest;
var url = "/?lorem=ipsum";

//GET request
xhr.open('GET', url); //Open the request with the specified url.
xhr.onreadystatechange = () => {
  //Checking if the request has finished and if it was successfull  
  if (xhr.readyState == 4 && xhr.status == 200) {
        console.log(xhr.responseText); //Printing out the response. 
        //You can also use xhr.responseXML
    }
}
xhr.send(); //This sends the request to the server with the specified params.