一、js:

  1. 要點:
    js通過ajax傳送header資訊php接收
  2. 完整程式碼:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Document</title>
            <script src="jquery.min.js"></script>
        </head>
        <body>
                <script>
                        $.ajax({
                                `url`:`http://localhost/index.php`,
                                `data`:{`sex`:`male`},
                                `beforeSend`:function(xhr){
                                    xhr.setRequestHeader(`name`,`lee`);
                                    xhr.setRequestHeader(`sex`,`male`);
                                    xhr.setRequestHeader(`height`,`168`);
                                },
                                `success`:function(data){
                                    console.log(data);
                                }
                            });
                </script>
        </body>
    </html>

    二、php:

  3. 要點:
    js通過ajax傳送header資訊php接收
  4. 完整程式碼:
    <?php
            header(`Access-Control-Allow-Origin:*`);
            header(`Access-Control-Allow-Credentials: true`);
            header(`Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS`);
            header(`Access-Control-Allow-Headers:WWW-Authenticate,Authorization,Set-Cookie,X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version,name,sex,height`);
            $header = apache_request_headers();
            var_Dump($header);exit;