Created
June 4, 2019 21:23
-
-
Save luisenriquecorona/4feb210ba8eb4d9d8e2a9f627fb0d428 to your computer and use it in GitHub Desktop.
Intercepting network requests HTTPrequest using the XMLHTTPRequest object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request; | |
if (window.XMLHttpRequest) { | |
request = new XMLHttpRequest(); | |
} else if (window.ActiveXObject) { | |
try { | |
request = new ActiveXObject('Msxml2.XMLHTTP'); | |
} catch (e) { | |
try { | |
request = new ActiveXObject('Microsoft.XMLHTTP'); | |
} catch (e) {} | |
} } | |
request.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
doSomething(this.responseText); | |
} | |
}; | |
// Open, send. | |
request.open('GET', '/some/url', true); | |
request.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment