Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
fetch.js 710 B
Newer Older
peter_rabbit's avatar
peter_rabbit committed
"use strict";

function fetchjson(url) {
    return new Promise((resolve, reject) => {
peter_rabbit's avatar
peter_rabbit committed
        const headers = new Headers();
        headers.append("Accept", "application/json");
        fetch(url, { mode: "no-cors", headers })
peter_rabbit's avatar
peter_rabbit committed
            .then(r => r.json())
            .then(r => resolve(r))
            .catch(e => reject(e));
    });
peter_rabbit's avatar
peter_rabbit committed
}
peter_rabbit's avatar
peter_rabbit committed

function fetchtext(url) {
peter_rabbit's avatar
peter_rabbit committed
    const headers = new Headers();
    headers.append("Accept", "text/html");
peter_rabbit's avatar
peter_rabbit committed
    return new Promise((resolve, reject) => {
peter_rabbit's avatar
peter_rabbit committed
        fetch(url, { mode: "no-cors", headers })
peter_rabbit's avatar
peter_rabbit committed
            .then(r => r.text())
            .then(r => resolve(r))
            .catch(e => reject(e));
    });
peter_rabbit's avatar
peter_rabbit committed
}
peter_rabbit's avatar
peter_rabbit committed

module.exports = {
peter_rabbit's avatar
peter_rabbit committed
    fetchjson,
    fetchtext,
};