search

Home  >  Q&A  >  body text

javascript - How to get the content of ajax request header using js?

  1. How to get ajax request header information in js

2. When I use XMLHttpRequest.header in the complete method of ajax, the value obtained is undefined. Is it undefined without this parameter?

3. If my above idea is wrong, please give me some advice

天蓬老师天蓬老师2736 days ago592

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-19 10:10:25

    Maybe this:
    var xhr = new XMLHttpRequest();
    xhr.open('get','',false);
    var headers = xhr.getAllResponseHeaders();
    xfr.send();

    reply
    0
  • PHPz

    PHPz2017-05-19 10:10:25

    var request = new XMLHttpRequest();
    request.open("GET", "foo.txt", true);
    request.send();
    request.onreadystatechange = function() {
    if(this.readyState == this.HEADERS_RECEIVED) {

    console.log(request.getAllResponseHeaders());

    }
    }

    reply
    0
  • Cancelreply