首页 > Web开发 > 详细

js通过ajax发送header信息php接收

时间:2018-01-30 12:02:12      阅读:223      评论:0      收藏:0      [点我收藏+]
一、js:
  1. 要点:
    技术分享图片
  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. 要点:
    技术分享图片
  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;

js通过ajax发送header信息php接收

原文:http://blog.51cto.com/12173069/2066641

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!