10 examples of 'jquery fetch' in JavaScript

Every line of 'jquery fetch' 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
41fetch(url, callback) {
42 this.url = url
43 this.timer = this.lazyShowLoading()
44 setTimeout(() => {
45 xhr({
46 url,
47 complete: () => {
48 clearTimeout(this.timer)
49 },
50 success: res => {
51 this.setState({xhr: 'success'})
52 callback ? callback(res) : this.handleSuccess(res)
53 },
54 error: ::this.handleError
55 })
56 }, this.props.delay || 0)
57}
15async function fetch(url) {
16 const response = await window.fetch(url);
17 return await response.text();
18}
21function loadXHR(url) {
22 return new Promise(function(resolve, reject) {
23 try {
24 var xhr = new XMLHttpRequest();
25 xhr.open('GET', url);
26 xhr.responseType = 'json';
27 xhr.onerror = function() {reject('Network error.');};
28 xhr.onload = function() {
29 if (xhr.status === 200) {resolve(xhr.response);}
30 else {reject('Loading error:' + xhr.statusText);}
31 };
32 xhr.send();
33 }
34 catch(err) {reject(err.message);}
35 });
36}
42function fetch (url, callback) {
43 callback(null, get(url));
44}
21function fetch (url) {
22 console.log(apiHost + url)
23 return new Promise((resolve, reject) => {
24 superagent
25 .get(apiHost + url)
26 .end((err,response) => {
27 if (err) {
28 console.log('error!' + url);
29 return
30 }
31 console.log('success!' + url);
32 resolve(JSON.parse(response.text))
33 })
34 })
35}
150function _$ajax(_url, _cb) {
151 if (_type(_url) == "string" && _type(_cb) == "function") {
152 return new _XHR({
153 url: _url,
154 _onSuccess: _cb
155 })
156 } else {
157 return new _XHR(_url)
158 }
159}
7async function fetchGet(url) {
8 const res = await fetch(url, {
9 method: 'GET',
10 mode: 'cors',
11 headers
12 });
13
14 const json = await res.json();
15
16 if (json.error && handler.onError) handler.onError(json);
17 return json;
18}
1function get(url, responseType, fn) {
2 var xhr = new XMLHttpRequest();
3 xhr.open('GET', url, true);
4 xhr.setRequestHeader('Authorization', 'Basic ZmVlZHRlc3Q6YWJjMTIz');
5 xhr.responseType = responseType;
6 xhr.onload = function() {
7 fn(xhr.response);
8 };
9 xhr.send();
10}
2fetch(url, params, CORSFlag = false) {
3 if (CORSFlag) {
4 return this.doCORSRequest(url, params.method, params.body, params.addRequestHeaders, params.onprogress);
5 } else {
6 return fetch(url, params);
7 }
8}
1export default function fetchJson(url, callback) {
2 const req = new XMLHttpRequest();
3 req.onload = () => {
4 if (req.status >= 200 && req.status < 300) {
5 const text = req.responseText;
6 try {
7 callback(null, JSON.parse(text));
8 } catch (e) {
9 callback(e, null);
10 }
11 } else {
12 callback(new Error(`${req.status}: ${req.statusText}`), null);
13 }
14 };
15 req.onerror = (e) => {
16 callback(e.error, null);
17 };
18 req.open('GET', url, true);
19 req.send(null);
20}

Related snippets