Skip to content

Instantly share code, notes, and snippets.

@Guidosalimbeni
Created April 15, 2022 11:45
Show Gist options
  • Save Guidosalimbeni/0637c362116261784f718603faa16451 to your computer and use it in GitHub Desktop.
Save Guidosalimbeni/0637c362116261784f718603faa16451 to your computer and use it in GitHub Desktop.
Submit to PHP connection to MySQL
let question = "test question';
let answer = 'test answer';
let form = new FormData();
form.append("question", question);
form.append("answer", answer);
fetch("http://www.guidosalimbeni.it/-- xxx xxx xxx --- .php", {
// URL
// body: JSON.stringify(form), // data you send.
body: new URLSearchParams(form),
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
headers: {
"content-type": "application/json",
},
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "no-cors", // no-cors, cors, *same-origin
redirect: "follow", // *manual, follow, error
referrer: "no-referrer", // *client, no-referrer
})
.then((resp) => {
console.log(resp);
})
.then((err) => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment