post method code example
Example 1: post method javascript code
const postData = async ( url = '', data = {})=>{
console.log(data);
const response = await fetch(url, {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
try {
const newData = await response.json();
console.log(newData);
return newData;
}catch(error) {
console.log("error", error);
}
}
Example 2: $.post javascript
$.post(
"path/to/your/php/file",
{
param1: "Value",
param2: "Value"
},
function(data) {
}
);
Example 3: http response methods
resource HTTP response method is made up of three
components:
Response Status Code ==> 200, 301, 404, 500
(these are the most common ones)
Response Header Fields ==> Date, Server, LastModified, Content-Type
Response Body ==> This is the data that comes
back to the client from the server.