Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript fetch post sending empty body

			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 :: express get request origin 
Javascript :: jq count outputs 
Javascript :: update replit node 
Javascript :: how to delay execution in nodejs 
Javascript :: sin in javascript 
Javascript :: last element of array javascript 
Javascript :: mousemove jquery 
Javascript :: click on child prevent click on parent 
Javascript :: condition in string interpolation angular 
Javascript :: multi stage node js dockerfile 
Javascript :: server error payload too large base64 image 
Javascript :: json datetime 
Javascript :: expo build android app bundle 
Javascript :: Creating new array from old array without impacting old array 
Javascript :: pipefy api search card field 
Javascript :: js replace all number 
Javascript :: how to hide source for react project 
Javascript :: js add to local storage 
Javascript :: filter number in string javascript 
Javascript :: vue router push 
Javascript :: mongoose pull each 
Javascript :: Please delete and rebuild the package with Ivy partial compilation mode, before attempting to publish. 
Javascript :: socket io get ip 
Javascript :: how to hide javascript element by class 
Javascript :: js greater than or equal to 
Javascript :: how to insert html in javascript 
Javascript :: node exec child_process ssh command password 
Javascript :: loopback unique field 
Javascript :: random alphabet javascript 
Javascript :: make string json object vue 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =