Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sending json data uing fetch is empty

			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;
?>

Comment

sending json data uing fetch is empty

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());
});
Comment

sending json data uing fetch is empty

fetch('/api/v1/users', {  
    method: 'post',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({ "user": {
      "email" : email,
      "password" : password
    }}),
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: cypress element length 
Javascript :: convert div to pdf javascript 
Javascript :: use axios cancel token in react.js useEffect 
Javascript :: text animation css and js 
Javascript :: return js 
Javascript :: express-session deprecated undefined resave option; provide resave option index.js:17:9 
Javascript :: what is functional programming 
Javascript :: javascript Strict Mode in Variable 
Javascript :: lodash uniqby 
Javascript :: get node by value neo4j 
Javascript :: how calculate number of digits of number 
Javascript :: jquery default value 
Javascript :: today tomorrow day after tomorrow button html and javascript 
Javascript :: express routers 
Javascript :: yup oneof 
Javascript :: timer stop button 
Javascript :: jqerrt get all img alt from string 
Javascript :: how to draw vertical dash line in react native 
Javascript :: how to add debounce in react redux js 
Javascript :: Get Input arrays 
Javascript :: set json column as index pandas dataframe 
Javascript :: react native notify user for new version of app 
Javascript :: reactjs wait for image to load from url 
Javascript :: how to give placeholder in input type date in angular 
Javascript :: javascript tousand seperator 
Javascript :: nested arrays javascript 
Javascript :: start nodemon under wsl2 
Javascript :: javascript remove elements from array with value 
Javascript :: show ad on facebook game 
Javascript :: adobe target triggerview 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =