Javascript


Fetch

Get

fetch('http://example.com/', {options})
.then(data => {
	console.log(data);
})
.catch(err => {
	console.log(err);
})

Post

fetch("http://example.com/api/example", {
    method: "POST",
    body: JSON.stringify({
        data: "lolipop",
    }),
    headers: {
        "Content-type": "application/json"
    }
})
.then(response => response.json())
.then(json => console.log(json));

Open url

New tab

window.open('http://example.com');

Change url

document.location = 'http://example.com/''

Last updated