使用请求标头发送cookie

时间:2013-01-17 08:07:33

标签: jquery

我正在尝试将我的cookie发送到外部网址,我无法看到我的cookie未在请求标头中设置,这导致从外部服务器抛出错误

以下是代码

<!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>Hello-Test</title>
  </head>
  <body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script src="https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js"></script>


    <script type="text/javascript">

    $(document).ready(function(){

        $.ajax({ 
            headers: { 
                "Accept ": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                "MY_COOKIE": $.cookie("MY_COOKIE"),
            }, 
            type: "GET",
            dataType: "json",
            url: 'external_url',
            success: function(data){        
                alert(data);
            },
            error: function(error) {
                alert(error);
            }
        });

    });

    </script>
  </body>
  </html>

任何想法,为什么在调用外部URL时没有在请求标头中设置cookie,而是在从浏览器尝试时正确获取数据。

谢谢, 普拉斯

0 个答案:

没有答案
相关问题