JS

POST & GET WITHOUT AN HTML FORM IN JAVASCRIPT

DATA var data = new URLSearchParams(); data.append("KEY", "VALUE"); data.append("name", "John Doe");

REDIRECT var url = "http://site.com/script?" + data.toString(); location.href = url;

URL QUERY STRING

01

DATA var data = new FormData();  data.append("KEY", "VALUE"); data.append("name", "John Doe"); 

AJAX POST var xhr = new XMLHttpRequest(); xhr.open("POST", "http://site.com"); xhr.onload = function () { console.log(this.response); };  xhr.send(data);

AJAX POST

02

DATA var data = new URLSearchParams(); data.append("KEY", "VALUE"); data.append("name", "John Doe");  var url = "http://site.com/script?" + data.toString();

AJAX GET var xhr = new XMLHttpRequest(); xhr.open("GET", url); xhr.onload = function() { console.log(this.response); };  xhr.send();

AJAX GET

03

DATA var data = new URLSearchParams(); data.append("KEY", "VALUE"); data.append("name", "John Doe"); 

FETCH fetch("http://mysite.com/SCRIPT", { method: "post", body: data }) .then((res) => res.text()) .then((txt) => { console.log(txt); }) .catch((err) => { console.log(error); });

FETCH POST

04

DATA var data = new URLSearchParams(); data.append("KEY", "VALUE"); data.append("name", "John Doe"); 

FETCH fetch("http://mysite.com/SCRIPT?" + data.toString(), { method: "get" }) .then((res) => res.text()) .then((txt) => { console.log(txt); }) .catch((err) => { console.log(error); });

FETCH GET

05