代码:
//use jQuery.ajax
$.ajax({
url: 'http://localhost:9733/Home/AjaxIndex',
type: 'get',
dataType: 'jsonp',
jsonpCallback: 'callback',
complete: function (jqXHR) {
console.log(jqXHR.getAllResponseHeaders())
console.log('=================================')
}
})
.always(function (d, s, jqXHR) {
console.log(jqXHR.getAllResponseHeaders())
console.log('=================================')
})
//use XMLHttpRequest
var xhr = new XMLHttpRequest()
xhr.open('get', 'http://localhost:9733/Home/AjaxIndex')
xhr.onload = function () {
console.log('load:', xhr.getAllResponseHeaders())
console.log('=================================')
}
xhr.send()
结果:
=================================
=================================
load: Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Content-Type: text/html; charset=utf-8
Cache-Control: private
所以我无法从jQuery.ajax获取响应头,但可以从XMLHttpRequest获取它吗?
如果我想获得它,我只能使用XMLHttpRequest?