I am developing login form in angular js using slim api integration.I am using multiple api in slim on this project but the error shown only when i am trying to login using post request. In that when i am send the login request using post request to the server it throwing the error on console like.
Failed to load resource: the server responded with a status of 404 (Not Found)
XMLHttpRequest cannot load http://example.com/Youin-api/v1/business/login. Response for preflight has invalid HTTP status code 404
My backend code:
$app->post('/business/login', function() use($app) {
$postvar = json_decode($app->request->getBody(), true);
verifyRequiredParams(array('emailid', 'pwd'));
$email = $postvar['emailid'];
$pwd = $postvar['pwd'];
// validating email address
validateEmail($email);
$db = new DbHandler();
$response = $db->loginBuser($email, $pwd);
// echo json response
echoRespnse(200, $response);
});
controller:
public function loginBuser($email, $pwd)
{
$response = array();
$stmt = $this->conn->prepare("SELECT BID from business_login_tbl WHERE emailid = ? and login_pwd = ?";
$stmt->bind_param("ss",$email,$pwd);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stmt->close();
if($num_rows > 0)
{
$response["code"] = "Success";
$response["error"] = false;
$response["user"] = $this->getBusinessuserByEmail($email);
}
else
{
$response["code"] = "failed";
$response["error"] = true;
$response["message"] = "Oops! Username of password Missmatch";
}
return $response;
}
my echo function:
function echoRespnse($status_code, $response) {
$app = \Slim\Slim::getInstance();
// Http response code
$app->status($status_code);
// setting response content type to json
$app->contentType('application/json');
echo json_encode($response);
}
i am using cors also:
$app = new \Slim\Slim();
$response = $app->response();
$response>header('Access-Control-Allow-Origin', 'http://example.com');
$response->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, X-authentication, X-client');
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
I am don't know what wrong with my front and back end code.Thanks in advance..!