const xhr = new XMLHttpRequest()
xhr.open('POST', './data/test.json', false)
xhr.onreadystatechange = () => {
console.log(xhr.readyState)
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(JSON.parse(xhr.responseText))
} else if (xhr.status ===404) {
console.log('404 not found')
}
}
}
const postData = {
"name": "zhangsan",
"password": 123
}
xhr.send(JSON.stringify(postData))
ajax手写post请求
最新推荐文章于 2025-04-25 18:11:06 发布