question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Track "state" of http request.

See original GitHub issue

Often elements in a page will show/hide based on the state of the http request.

this.registerState = 'sending';

this.$http.post('/auth/register, {}, function () {
    this.registerState = 'sent';
}, function () {
    this.registerstate = 'error';
});

This can get extremely redundant. It would be nice if there was a parameter that could be set for the request and the contexts data would automatically get updated.

this.$http.post('/auth/register, {}, function () {
}, {
    state: 'registerState'
});

Then in our view we just have access to registerState and don’t need to constantly write up the logic.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nblackburncommented, Mar 21, 2016
Vue.http.get('https://example.com/api/v1/authenticate', {username: 'username', password: 'password'}, {
    xhr: {
        onreadystatechange: function(event) {
          console.log(event);
        }
    }
});

You could do this via the third argument on a request and attaching a callback to the xhr object.

On a side note, try and keep questions in the forums as this is the wrong place to be asking them.

0reactions
nblackburncommented, Mar 21, 2016

I know it’s not a question, i was simply stating it was possible at present even though i prefer your proposal.

That being said, it would also be nice to extend this out to track request progress too which would be useful for displaying upload/download progress.

I have updated my example to cover all states rather than just progress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP request methods - MDN Web Docs
Chrome Edge CONNECT Full support. ChromeYes. Toggle history Full support. Edge12. Toggle history DELETE Full support. ChromeYes. Toggle history Full support. Edge12. Toggle history GET Full...
Read more >
Track state of HTTP request and add / remove spinner on ...
I need to create a spinner, wait for downloading to be ready and remove the spinner. jQuery code I've written: $(document).ajaxStart(apex.
Read more >
HTTP - Methods - Tutorialspoint
TRACE Method. The TRACE method is used to echo the contents of an HTTP Request back to the requester which can be used...
Read more >
HTTP State Management
HTTP is a stateless (or non-persistent) protocol. Each request is treated by its own. A request will not know what was done in...
Read more >
HTTP/1.1: Method Definitions
TRACE allows the client to see what is being received at the other end of the request chain and use that data for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found