1. 程式人生 > >php API 跨域請求

php API 跨域請求

處理PHP API 跨域請求:

設定API相應的http頭,讓該介面支援跨域請求

   header("Content-type: application/json");
   header("Access-Control-Allow-Origin:  *" );
    header("Access-Control-Allow-Methods: GET, OPTIONS, POST");
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-Requested-With, Origin");