1const postData = async ( url = '', data = {})=>{
2 console.log(data);
3 const response = await fetch(url, {
4 method: 'POST',
5 credentials: 'same-origin',
6 headers: {
7 'Content-Type': 'application/json',
8 },
9 // Body data type must match "Content-Type" header
10 body: JSON.stringify(data),
11 });
12
13 try {
14 const newData = await response.json();
15 console.log(newData);
16 return newData;
17 }catch(error) {
18 console.log("error", error);
19 }
20 }
21
1//$.post with jQuery
2
3$.post(
4 "path/to/your/php/file",
5 {
6 param1: "Value",
7 param2: "Value"
8},
9 function(data) {
10 //Callback here
11 }
12);
13