@pamzz wrote:
When run the app shows an Error
Access to XMLHttpRequest at ‘https://www.pamz.co.jp/api/process_api.php’ from origin ‘http://localhost:8101’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
access_provider.ts
export class AccessProviders{ server:string='https://www.pamz.co.jp/api/'; constructor(private http:HttpClient ) { } postData(body,file){ let headers=new HttpHeaders({ 'Content-Type':'application/json; charset=UTF-8' }); let options= { headers : headers } return this.http.post(this.server + file , JSON.stringify(body),options) .timeout(590000) .map(res=>res); } }
process_api.php
header('Access-Control-Allow-Orgin: *'); header("Access-Control-Allow-Credentials: true"); header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS"); header("Access-Control-Allow-Headers: Origin,Content-Type,Authorization,Accept,X-Requested-With,x-xsrf-token"); header("Content-Type: application/json;charset=utf-8"); include "config.php"; $postjson=json_decode(file_get_contents('php://input'),true); $today=date('Y-m-d H:i:s'); if($postjson['aksi']=="process_register"){ $checkmail=mysqli_fetch_array(mysqli_query($mysqli,"SELECT email_address FROM register WHERE email_address='$postjson[email_address]'")); if($checkmail['email_address']==$postjson['email_address']){ $result=json_encode(array('success'=>false,'msg'=>'Email Already Registered')); }else{ $password=md5($postjson['password']); $insert = mysqli_query($mysqli,"INSERT INTO register SET your_name ='$postjson[your_name]', email_address ='$postjson[email_address]', password ='$password', confirm_pass ='$postjson[confirm_pass]', created_at ='$today' "); if($insert){ $result=json_encode(array('success'=>true,'msg'=>'Register Successfully')); }else{ $result=json_encode(array('success'=>false,'msg'=>'Register error')); } } echo $result; }
How to solve…Any one Help…
Posts: 1
Participants: 1