How to get Response Header location from jQuery Get?

前端 未结 3 1168
猫巷女王i
猫巷女王i 2020-12-31 05:21

So I am trying to get the location from a header response via jQuery get. I tried using getResponseHeader(\'Location\') and getAllResponseHeaders() but they both seem to ret

3条回答
  •  孤独总比滥情好
    2020-12-31 05:47

    jQuery abstracts the XMLHttpRequest object in a so-called "super set" that does not expose the responseURL field. It's in their docs where they talk about the "jQuery XMLHttpRequest (jqXHR) object"

    For backward compatibility with XMLHttpRequest, a jqXHR object will expose the following properties and methods:
    
    readyState
    responseXML and/or responseText when the underlying request responded with xml and/or text, respectively
    status
    statusText
    abort( [ statusText ] )
    getAllResponseHeaders() as a string
    getResponseHeader( name )
    overrideMimeType( mimeType )
    setRequestHeader( name, value ) which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one
    statusCode( callbacksByStatusCode )
    No onreadystatechange mechanism is provided, however, since done, fail, always, and statusCode cover all conceivable requirements.
    

    As you can see there is no way to get hold of the response URL because the jqXHR API does not expose it

提交回复
热议问题