XHR的方法

1.abort()终止当前请求
调用时机:在send()之后
2.setRequestHeader()设置请求头信息

//用在POST方式请求,请求头中的Content-Type字段用来告诉服务器,
//浏览器发送的数据是什么格式的
// xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
//对应的数据格式(form表单用的enctype默认就是application/x-www-form-urlencoded)
// xhr.send("username=zjh&age=18")

xhr.setRequestHeader("Content-Type","application/json")
// 对应的数据格式
xhr.send(JSON.stringify({username:'zjh',age:18}))
上一篇:AJAX请求头Content-type


下一篇:Request请求:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String conta