home.ts
this.LocationProvider.getSpecificLocation(districtid,head).subscribe(res=>{
console.log(res),
err=>{
console.log(err)
}
})
我必须解析响应以在视图中显示数据。我无法res.json()
它将错误显示为ERROR SyntaxError: Unexpected token < in JSON at position 1
。
ws.php
public function location(){
$this->load->model('Coolmodel','m',true);
$retval = array();
if($this->input->method() === 'post') {
$obj = json_decode($this->input->raw_input_stream);
$id = $obj->id;
$retval['locations']=$this->m->getlocation($id);
}
else{
$retval['status'] = '1';
$retval['district'] = $this->m->getdistrict();
}
header('Content-Type: application/json');
echo json_encode($retval, JSON_UNESCAPED_UNICODE);
}
这是我的PHP代码,我应该进行任何修改吗?