JS

SEND GET PARAMS WITH JAVASCRIPT FETCH

URL QUERY PARAMETERS

01

URL & DATA var url = new URL("http://site.com/"); var data =   { name: "jon", email: "jon@doe.com" }; for (let k in data)  {   url.searchParams.append(k, data[k]); }

FETCH fetch(url) .then((res) => { return res.text(); }) .then((txt) => { alert(txt); });

MANUAL BUILD URL PARAMS

02

URL & DATA var url = "http://site.com/"; url += "?"; for (let k in data)  {   url += k + "=" + data[k] + "&"; } url = encodeURI(url.slice(0, -1));

FETCH fetch(url) .then((res) => { return res.text(); }) .then((txt) => { alert(txt); });