Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

why request body is empty when using fetch

			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

PREVIOUS NEXT
Code Example
Javascript :: cursor to pointer in react 
Javascript :: vue redirect to route 
Javascript :: stun server 
Javascript :: .replace is not a function 
Javascript :: xmlhttprequest post form 
Javascript :: add last element in array javascript 
Javascript :: regular expression to validate if the given input is valid Indian mobile number or not 
Javascript :: react material modal custom backdrop 
Javascript :: javascript before reload page alert 
Javascript :: express js params 
Javascript :: make created element brighter 
Javascript :: node js get ipv4 ip 
Javascript :: expo android built is huge 
Javascript :: Check your page, maybe you import jQuery library twice, the slim version or it is missing. 
Javascript :: pipefy search card by custom field 
Javascript :: remove undefined from array javascript 
Javascript :: remove event listener react hooks 
Javascript :: set html attribute jquery 
Javascript :: regex match number javascript 
Javascript :: add download buttons in datatable 
Javascript :: javascript size of variable in kb 
Javascript :: exponent form calculator in angular 
Javascript :: js remove element by tagname 
Javascript :: character to ascii javascript 
Javascript :: CocoaPods could not find compatible versions for pod "ReactCommon/jscallinvoker" 
Javascript :: javascript reverse string without reverse method 
Javascript :: president zelensky 
Javascript :: find vowel & consonants in a string java script 
Javascript :: moment js date diff 
Javascript :: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =