リンク(PHPサーバ)からオブジェクトのリストを取得しようとするとエラーが発生します。マルチ原点要求(クロスオリジンリクエスト)のエラーHTTP GETオブジェクトリスト
ブロッキング://localhost/eReport/index.php:「同じ 源」ポリシーは HTTPに位置するリモートリソースへのアクセスを許可しません。理由: CORS 「Access-Control-Allow-Headers」CORSヘッダーに「アクセス制御認可元」トークンがありません。
このリンクにはこのtutoのようなヘッダーを追加しましたが、まだこのエラーがあります。
お願いします。
私のサービスページ:
@Injectable()
export class ReportService{
private baseUrl: string = 'http://localhost/report/reports.php';
constructor(private http : Http){}
getAll(): Observable<Report[]>{
let report$ = this.http
.get(`${this.baseUrl}`, { headers: this.getHeaders()})
.map(mapReports);
return report$;
}
private getHeaders(){
// I included these headers because otherwise FireFox
// will request text/html
let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
return headers;
}
get(id: number): Observable<Report> {
let report$ = this.http
.get(`${this.baseUrl}/report/${id}`, {headers: this.getHeaders()})
.map(mapReport);
return report$;
}
私のPHPページ
header("Access-Control-Allow-Origin: *");
$tab = array(
array('id'=> '12', 'name'=> 'test','description' => '2018-04-01','url'=>'../../../assets/img/chat1.png'),
array('id'=> '13', 'name'=> 'test','description' => '2018-04-01','url'=>'../../../assets/img/highcharts.png')
);
echo json_encode($tab);
?>
あなたは、エラーのどのような種類を取得しましたか? – ivanasetiawan
複数の送信元要求(クロスオリジン要求)のブロック:「同じ送信元」ポリシーは、http://localhost/eReport/index.phpにあるリモートリソースへのアクセスを許可しません。理由:CORSの「Access-Control-Allow-Headers」CORSヘッダーに「アクセス制御認可元」トークンがありません。 – Yago
これはサーバー側からのもので、異なるドメイン間で要求を許可する必要があります –