jquery.cookie.js使用


1、下載jquery.cookie.js

官網:http://plugins.jquery.com/cookie/

http://pan.baidu.com/s/1mgynA8g

2、使用方法

$.cookie('the_cookie'); // 獲得cookie
$.cookie('the_cookie', 'the_value'); // 設置cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); //設置帶時間的cookie
$.cookie('the_cookie', '', { expires: -1 }); // 刪除
$.cookie('the_cookie', null); // 刪除 cookie
$.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});//新建一個cookie 包括有效期 路徑 域名等

3、測試,HTML頁中寫一個cookie值,然后用ajax調用一個nginx請求,nginx里用LUA獲取到這個cookie值再返回給HTML頁最后alert出來。
HTML頁

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script>
    $.cookie('uid', 'dsideal');
</script>
</head>
<body>
    <p>
        <input type="button" value="test" onclick="test();" />
    </p>
</body>
<script>
    function test() {
        $.ajax({
            type : "GET",
            async : false,
            url : "http://10.10.3.205/getCookie",
            success : function(res) {
                alert(res);
            }
        });
    }
</script>
</html>

nginx

location /getCookie{
            content_by_lua '
                ngx.header.content_type = "text/plain;charset=utf-8"
                ngx.say(ngx.var.cookie_uid)
            ';
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM