PageSourceSearch

https://gatesopenresearch.org/js/shared_scripts/ajax.js

js gatesopenresearch.org collected 2026-09-24 17:16:07 UTC 1,568 bytes, 55 lines download raw bytes

1class Ajax {
2  constructor() {
3    this.defaultSettings = {
4      method: 'GET',
5      endpoint: null,
6      responseType: 'json',
7      requestHeaders: null,
8      timeout: 0,
9      data: null,
10      successCode: [200],
11      error: null
12    };
13  }
14
15  execute(userSettings) {
16    return new Promise((resolve, reject) => {
17      const settings = extend(true, this.defaultSettings, userSettings);
18
19      if (settings.endpoint === null) {
20        console.warn('No endpoint specified');
21        return;
22      }
23
24      const xhr = new XMLHttpRequest();
25
26      xhr.open(settings.method, settings.endpoint);
27      // commenting out as this causes problems when a successful call produces JSON but an unsuccessful one isn't
28      // xhr.responseType = settings.responseType;
29      xhr.timeout = settings.timeout;
30
31      if (settings.requestHeaders) {
32        for (const requestHeader of settings.requestHeaders) {
33          xhr.setRequestHeader(Object.keys(requestHeader)[0], Object.values(requestHeader)[0]);
34        }
35      }
36
37      xhr.addEventListener('load', () => {
38        const response = xhr.response,
39          output = (settings.responseType === 'json') ? F1000.ParseAsJson(response) : response;
40
41        if (xhr.readyState === 4 && settings.successCode.indexOf(xhr.status) > -1) {
42          resolve(output);
43        } else {
44          reject(settings.error ? settings.error : output);
45        }
46      });
47
48      xhr.addEventListener('error', () => {
49        reject(settings.error ? settings.error : output);
50      });
51
52      xhr.send(settings.data);
53    });
54  }
55}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.