How to check if HTTP requests are open in browser?Ask Questions

 Posted on 10/24/2019

Is there an easy way to detect if an XMLHttpRequest is active in the browser window? Or how many are active? ie. Is there a way to detect if there are any AJAX calls active in my browser window?

Extension of question: Using javascript is there a way I can see if any XMLHttpRequests are open? Such as "window.XMLisActive()" or something like that?

Share On: facebook gplus twitter
profile
Asked by Aidam Turner on 10/24/2019 Score: 62 points
Add Comment:

Comments

1 Answers

0 Corrected Answers
Aproved Answers
0
Profile
Answered by Ned Batchelder on 10/25/2019 9:39:01 AM Score: 41 points

There is not a way to detect an open connection from JS unless you write a wrapper for XmlHttpRequest (or monkey patch it) that keeps track of opened connections.

Here's kidcapital's monkey patch, not sure if it's perfect, but it's a good start

(function() {
var oldOpen = XMLHttpRequest.prototype.open; window.openHTTPs = 0;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
            window.openHTTPs++;
            this.addEventListener("readystatechange", function() {
                       if(this.readyState == 4) {
                               window.openHTTPs--;
                       }
            }, false);
   oldOpen.call(this, method, url, async, user, pass);
  }
})();

Comments

Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
Password
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.