Within my controller, I am initiating an http
request as shown below:
var postData = { action: 'getTasksByProjectSlug', slug: 'inbox' }
$http({
url: 'http://localhost/toodloo/api/kernel.php',
method: 'POST',
data: postData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function( data, status, headers, config ){
console.log( data );
}).error(function( data, status, headers, config ) {
console.log( status );
});
Furthermore, in the file kernel.php
, the following snippet exists:
class Kernel
{
function __construct( $requestData )
{
if ( ( isset( $requestData ) === false ) || empty( $requestData ) ) {
die( 'No data received!' );
}
$this->findRoute( $requestData );
}
public function findRoute( $requestData ) {
...
} else if ( ( $requestData['action'] === 'getTasksByProjectSlug' ) && isset( $requestData['slug'] ) ) {
$this->getTasksByProjectSlug( $requestData['slug'] );
} else {
...
}
public function getTasksByProjectSlug( $slug ) {
$project = new Project;
$tasks = $project->getTasksByProjectSlug( $slug );
$json = json_encode( $tasks );
echo $json;
return $json;
}
}
$kernel = new Kernel( $_POST );
The issue at hand is that when console.log( data );
within the success
section of the $http
call only logs 'No data received'. This indicates that the API responds with this message when the condition
( isset( $_POST ) === false ) || empty( $_POST ) )
is met. Therefore, it seems like the server is receiving the request but not the associated data var postData = { action: 'getTasksByProjectSlug', slug: 'inbox' }
.
If anyone could provide insight into what might be causing this issue or why the postData
is not reaching the server side, I would greatly appreciate it.
P.S: I have attempted using data: JSON.stringify(postData)
to no avail.