1. let xhr = new XMLHttpRequest()
    2. console.log(xhr.readyState);
    3. xhr.open('get', 'http://www.baidu.com')
    4. console.log(xhr.readyState);
    5. xhr.send()
    6. console.log(xhr.readyState);
    7. // onreadystatechange 监听 readyState 的变化 状态 4 为请求已完成
    8. xhr.onreadystatechange = function () {
    9. console.log(xhr.readyState);
    10. if (xhr.readyState == 4 && xhr.status == 200) {
    11. console.log('请求成功');
    12. }
    13. }