title: Handling GET 301/302 responses with JavaScript in Vue.js
body: <p>I need to print some 301/302 response headers with JavaScript: I saw lots of answers for Angular, but I’m using Vue.js to get the results. Well, it doesn’t really matter since it’s mainly a JavaScript issue… I mean, <strong>I’m not just interested in a Vue.js-<em>only</em> solution</strong>, it could and should work everywhere. As a front-end developer, I can’t manually create a scenario in which my project returns a redirect in its own server and finding a random remote page that does it without CORS limitations is hard. To be even more clear, I need to get <code>status</code> code and <code>statusText</code> of 301/302 responses (as well as the <code>Location</code> of the new page) before the redirection, then the full headers of the redirected page. Now I can retrieve only these last, because <a href="https://github.com/pagekit/vue-resource/blob/develop/docs/http.md" rel="nofollow noreferrer">the default <code>this.$http.get();</code> request</a> created by <code>vue-resource</code> doesn’t seem to store the first in an object. What I’m asking here is if there’s a way to store the redirection response in a variable too, then to show both. I don’t know if switching to <code>axios</code> could be preferrable — since I’m pretty new to Vue.js. My component’s method is as follow:</p>
  
  <pre><code>getRequest: function() {
    this.$http.get(this.url)
      .then(function(response) {
        if (response.ok) {
          if (response.status === 301 || response.status === 302) {
            // show the redirecting response
          }
        // show the redirected response
        }
      }
  </code></pre>
  
  <p>EDIT: <a href="https://github.com/fedtti/http-requests" rel="nofollow noreferrer">the sources for this project</a> are on GitHub; when you send a GET request and the response says 301/302, you should be able to see three columns instead of two where the second shows details of the redirecting response headers.</p>