10 examples of 'xhr open' in JavaScript

Every line of 'xhr open' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
17open(method, url) {
18 this.opts.method = method;
19 this.url = url;
20}
114public open(url:string, method:string = "GET"):void {
115 this._url = url;
116 if (this._xhr) {
117 this._xhr.abort();
118 this._xhr = null;
119 }
120 this._xhr = new XMLHttpRequest();
121 this._xhr.onreadystatechange = this.onReadyStateChange;
122 this._xhr.onprogress = this.updateProgress;
123 this._xhr.open(method, url, true);
124 if (this._responseType != null) {
125 this._xhr.responseType = this.responseType;
126 }
127 if (this._withCredentials != null) {
128 this._xhr.withCredentials = this._withCredentials;
129 }
130 if (this.header != null) {
131 this._xhr.setRequestHeader(this.header, this.headerValue);
132 }
133}
33open(method, url) {
34 // Do nothing.
35}
29open(method: string, url: string) {
30 this.method = method;
31 this.url = url;
32}
98open(method, url, async = true) {
99 if (!async) {
100 throw new Error('async = false is not supported.');
101 }
102 if (isRequestMethodForbidden(method)) {
103 throwError('SecurityError', `Method "${method}" forbidden.`);
104 }
105 method = normalizeHTTPMethodName(method);
106 // Skip parsing the url and setting the username and password
107
108 this._terminateRequest();
109
110 // Set variables
111 this._sendFlag = false;
112 this._uploadListenerFlag = false;
113 this.method = method;
114 this.url = url;
115 this.requestHeaders.reset();
116 this._response = this._networkErrorResponse();
117 if (this._readyState !== MockXhr.OPENED) {
118 this._readyState = MockXhr.OPENED;
119 this._fireReadyStateChange();
120 }
121}
66function xhr(url, ifexists, ifnotexists, retry_interval) {
67 var retry_time = retry_interval || 5;
68 var req = new XMLHttpRequest();
69 console.log("Fetching: " + url);
70 req.open("GET", url);
71 req.onreadystatechange=function(){
72 if (req.readyState == 4){
73 var status=req.status;
74 if ((status == 200) || (status == 301) || (status == 302)) {
75 ifexists(url, req);
76 } else {
77 ifnotexists(url, req);
78 setTimeout(function() { xhr(url, ifexists, ifnotexists, retry_time + 5).send(null); }, retry_time);
79 }
80 }
81 };
82 return req;
83};
59open() {
60 return this._callNative('open', arguments);
61}
1export default function xhr(url) {
2 let r = new window.XMLHttpRequest();
3 r.responseType = "arraybuffer";
4 r.open("get", url, true);
5 r.send();
6
7 return new Promise((resolve, reject) => {
8 r.addEventListener("load", e => resolve(e.target));
9 r.addEventListener("error", reject);
10 });
11}
3function xhr(method, url, data, callback){
4 var x = new XMLHttpRequest();
5 x.onreadystatechange = function(){
6 if(x.readyState == 4){
7 if(x.status == 200 || x.status == 204){
8 callback(x.responseText);
9 }else{
10 console.error(method, url, x.status, x.statusText, x.responseText);
11 }
12 }
13 };
14 x.open(method, url);
15 x.send(data);
16}
116function xhr(self){
117 var req = win.XMLHttpRequest ? new XMLHttpRequest() : null
118 if(req === null) throw new Error("Browser (" + Browser.toString() +") cannot handle Requests")
119 self.request = req
120 return req
121}

Related snippets