-1

In below code, value not meet when its calling using Ajax. $pos always return null value

<?php
header('Access-Control-Allow-Origin: *');
header('data-Type:application/json; charset=UTF-8');
header('Content-Type: application/json; charset=UTF-8');
//ini_set('display_errors',1);
           //error_reporting(E_ALL);
include("connect.php");
include("datalayer.php");
$pos = json_decode(file_get_contents('php://input'));
$InvalidLogon =(array) new \stdClass();
?>

AJAX Call

var settings = {
  "url": "login.php",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json"
  },
  "data": JSON.stringify({"emp_id":"emp1","password":"password"}),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

1 Answers1

0

Change the below code

$pos = json_decode(file_get_contents('php://input'));

with

echo $pos = json_decode(file_get_contents('php://input'));
John Doe
  • 1,401
  • 1
  • 3
  • 14