ajax
+ js 向后端索要数据的方式(技术)
基本步骤
1. 创建ajax 对象
const xhr = new XMLHttpRequest()
2. 配置本次的请求信息
xhr.open(请求方式, 请求地址, 是否异步)
3. 绑定事件
xhr.onload = function () { xhr.responseText }
4. 发送请求
xhr.send()
发送一个带有参数的 get 请求
const xhr = new XMLHttpRequest()
xhr.open('GET', '地址?key=value&key2=value2')
xhr.onload = function () { ... }
xhr.send()
发送一个带有参数的 post 请求
const xhr = new XMLHttpRequest()
xhr.open('GET', '地址')
xhr.onload = function () { ... }</