let datastring = {
submit: true,
firstname: 'Kumar',
lastname: 'D',
email: 'kumar@test.com'
}
fetch('http://localhost.com/index_json_data.php', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(datastring),
}).then(res => res.json())
.then(res => console.log('after submit', res));
///// index_json_data.php PHP Code //////////
<?php
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json);
print_r($data);
// Converts it into a PHP Array
$data = json_decode($json,true);
exit;
?>
var myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
fetch('/contact-form', {
method: 'POST',
headers: myHeaders,
mode: 'cors',
cache: 'default',
body: JSON.stringify(fields)
}).then(() => {
dispatch(contactFormSubmitSuccess());
});
fetch('/api/v1/users', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ "user": {
"email" : email,
"password" : password
}}),
})