• 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)
                ';
            }
  • 相关阅读:
    中断
    按键
    uart stdio的移植1
    串口通信实战
    串口通信相关知识详解
    SOC时钟
    arm-linux-ld: cannot find sdram_init.o
    SDRAM初始化
    代码重定位实战
    s5pv210的启动过程
  • 原文地址:https://www.cnblogs.com/kgdxpr/p/3652445.html
Copyright © 2020-2023  润新知