Skip to content

Latest commit

 

History

History
47 lines (41 loc) · 1.03 KB

Javascript.md

File metadata and controls

47 lines (41 loc) · 1.03 KB

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/''