fetchJSON

feature/2.0-sales-trade
Lei OT 2 years ago
parent 4a904ff71d
commit 2e831d7388

@ -1,3 +1,5 @@
import { HT_HOST }from "../config";
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
@ -20,8 +22,16 @@ export function fetchText(url) {
});
}
export function fetchJSON(url) {
return fetch(url)
export function fetchJSON(url, data) {
let params = '';
let ifp = '';
if (data) {
params = new URLSearchParams(data).toString();
ifp = params ? '?' : ifp;
}
ifp = url.includes('?') ? '' : ifp;
const host = /^https?:\/\//i.test(url) ? '': HT_HOST;
return fetch(`${host}${url}${ifp}${params}`)
.then(checkStatus)
.then(response => response.json())
.catch(error => {

Loading…
Cancel
Save