Hi fuse,
I tried to pass the obj value to server side. But problem is API not receiving the request body. But when I use the postman app for send request it’s work properly. But here It is giving empty array. Can anyone please support me…
function request(){
var status = 0;
var response_ok = false;
var obj = {"imei":"132323"};
fetch('http://localhost/api.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(obj),
}).then(function(response) {
status = response.status;
response_ok = response.ok;
return response.json();
}).then(function(responseObject) {
// Do something with the result
}).catch(function(err) {
// An error occurred somewhere in the Promise chain
});
}
module.exports = {
check
};
</JavaScript>
<?php
$imei = $_REQUEST['imei'];
error_log("checking imei number =>".JSON_ENCODE($_REQUEST));
if($imei=="354891062577725"){
error_log("true");
$data_array['status'] = true;
echo json_encode($data_array);
}else{
error_log("false");
$data_array['status'] = false;
echo json_encode($data_array);
}
?>