// 1.创建XMLHttpRequest对象,建议变量名叫xhr 一般在网站中都是用xhr代表ajax请求
var xhr = new XMLHttpRequest()
// 2.调用open方法,设置请求方式和请求路径
// 参数1:请求方式 参数2:请求路径url(下面是我随便写的一个路径)
xhr.open('get', 'https://autumnfish.cn/api/joke')
// 3.监听响应完成事件
xhr.onreadystatechange = function () {
// 在这个事件里面才能拿到服务器返回的数据
console.log(xhr.responseText);
}
// 4.调用send方法发送请求
xhr.send();

<script>
// 1.创建XMLHttpRequest对象
var xhr = new XMLHttpRequest()
//2. 调用open方法设置请求方式、请求路径
// 参数1:请求方式 参数2:请求路径url(下面是我随便写的一个路径)
xhr.open('post', 'https://autumnfish.cn/api/user/check');
//3. 监听响应完成事件
xhr.onreadystatechange = function () {
console.log(xhr.responseText);
}
// 4.设置请求头(注意:post请求必须设置请求头,用formData方法不用设置请求头)
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
//5. 发送请求
// 多个参数之间也是用&连接
xhr.send('username=吖吖');
</script>
