How can I use response-native with php with fetch return data always null

My return is always zero. I can't seem to work. How can I use native-native with php with fetch json. can anyone help?

Php

$myArray = array(); $myArray['lat'] = $_POST['lat']; $myArray['lng'] = $_POST['lng']; echo $_POST['lat']; 

Jet sampling

 fetch(url, { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ lat: region.latitude, lng: region.longitude }) }) .then((response) => response.json()) .then((responseData) => { console.log(responseData); }) .catch((error) => { console.warn(error); }) .done(); 
+6
source share
1 answer

You will have to use file_get_contents ('php: // input') if php cannot see the data.

 $json = json_decode(file_get_contents('php://input'), true); $myArray = array(); $myArray['lat'] = $json['lat']; $myArray['lng'] = $json['lng']; $myArray['status'] = 'success'; echo json_encode($myArray); 
+8
source

All Articles