I am writing a post method in angular to post some data I am returning JSON in Codeigniter.
this is service:
public userlogin(data) {
let uploadURL = `myurl`;
const requestOptions: Object = {
responseType: 'json'
}
return this.http.post<any>(uploadURL, data,requestOptions).pipe(map((responce) => {
console.log(responce);
return responce;
})
);
}
In my component:
this.services.postuser(formData).subscribe(
(data) => {
console.log(data);
}
);
following error, I am getting in the console
and here is a screenshot to my network tab where the response is JSON
I have gone through a lot of stack overflow questions and answers but the solution is not working for me. I also changed post method response from JSON to text and response type in post method to text still receiving the same error.
backend function for post:
public function user_login()
{
if(is_array($_POST) && sizeof($_POST) >0){
$where_array = array(
'username'=>$this->input->post('username'),
'password'=>$this->input->post('password')
);
$result = $this->Admin_model->checkuser($where_array);
// print_r($result); die;
if($result == "user not found" || $result == "incorrect password")
{
$json_data = array("Code"=>"1","data"=>$result);
echo json_encode($json_data, JSON_UNESCAPED_SLASHES);
}else{
$json_data = array("Code"=>"0","data" => "Login successfull");
echo json_encode($json_data, JSON_UNESCAPED_SLASHES);
}
}
}