var xhr = new XMLHttpRequest ();
xhr.open('get|post' , url)
post --?? xhe.setRequestHeadr('Content-Type',? "application/x-www-form-urlencoded")
xhr.send()
xhr.readstatechange = function(){
xhr.onload = function(){
console.log(xhr.responseText)
}
}
上傳文件的? 時(shí)候? ---?? post?
var fd = new FormData(? 表單的DOM對(duì)象? )? 自動(dòng)拿到的是代碼有name 字段?
fd.append('avatar',? this.files[0])
fd.set()
var? xhr? = new XMLHttpRequest ();
xhr.open('get|post' , url)
xhr.send(fd)
xhr.readstatechange = function(){
xhr.onload = function(){
console.log(xhr.responseText)
}
}
上傳圖片
$.ajax({
processData: false,
contentType: false
})
jsonp
$.ajax({
dataType:"jsonp"
})
jsonp? 原理? script src 發(fā)送請(qǐng)求? ?callback=fn
前端 script src = "baidu.com?callback=fn"
后端? res.send? ( req.query.callback? +? '(? )' )