A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/uiv-lib/uiv/commit/b50574783df34a90aa4ec0f8288d3690c5f3d6f1 below:

use fetch api for internal ajax · uiv-lib/uiv@b505747 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+1

-103

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+1

-103

lines changed Original file line number Diff line number Diff line change

@@ -1,43 +1,3 @@

1 -

import { isFunction, isExist, hasOwnProperty } from './object.utils';

2 - 3 1

export function request(url, method = 'GET') {

4 -

const request = new window.XMLHttpRequest();

5 -

const data = {};

6 -

const p = {

7 -

then: (fn1, fn2) => p.done(fn1).fail(fn2),

8 -

catch: (fn) => p.fail(fn),

9 -

always: (fn) => p.done(fn).fail(fn),

10 -

};

11 -

const statuses = ['done', 'fail'];

12 -

statuses.forEach((name) => {

13 -

data[name] = [];

14 -

p[name] = (fn) => {

15 -

if (fn instanceof Function) data[name].push(fn);

16 -

return p;

17 -

};

18 -

});

19 -

p.done(JSON.parse);

20 -

request.onreadystatechange = () => {

21 -

if (request.readyState === 4) {

22 -

const e = { status: request.status };

23 -

if (request.status === 200) {

24 -

let response = request.responseText;

25 -

for (const i in data.done) {

26 -

/* istanbul ignore else */

27 -

if (hasOwnProperty(data.done, i) && isFunction(data.done[i])) {

28 -

const value = data.done[i](response);

29 -

if (isExist(value)) {

30 -

response = value;

31 -

}

32 -

}

33 -

}

34 -

} else {

35 -

data.fail.forEach((fail) => fail(e));

36 -

}

37 -

}

38 -

};

39 -

request.open(method, url);

40 -

request.setRequestHeader('Accept', 'application/json');

41 -

request.send();

42 -

return p;

2 +

return fetch(url, { method }).then((res) => res.json());

43 3

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4