zoukankan      html  css  js  c++  java
  • ajax设置cookie.有效期为1天(cookie名前缀统一为order_sn_,方便之后获取使用)

    1.html(tp5遍历表单元素)

    <td {if condition="$order['warning'] eq 1" } style="background: red" {/if}>
      {$order.diff_day}
    </td>
    <td>
      {if condition="$order['warning'] eq 1"}
          <span order_sn="{$order.order_sn}"class="dis_no default ignoreStock {$order.order_sn}" id="ignoreStock">忽略提示</span>
       {/if}
    </td>

    2.js

     $(".ignoreStock").on("click", function () {
            var order_sn = $(this).attr("order_sn");
            $(this).parent().prev().css("background", "");  //单元格取消红色背景颜色
            $(this).text('');   //操作去除‘忽略提示’文字
            $.ajax({
                url: "/supplierbuyer/order/ignoreStock",
                data: {
                    "order_sn": order_sn,
                },
                type: "POST",
                dataType: "JSON",
                success: function (data) {
                    console.log(data);
                    if (data.status == true) {
                    } else {
                        console.log(data);
                        return false;
                    }
                }
            });
        });

    3.php

        /**
         * 忽略周期预警
         */
        public function ignoreStock()
        {
            $order_sn = Request::instance()->post('order_sn');
            $name = 'order_sn_' . $order_sn;
            Cookie::set("$name", $order_sn, 86400);
    
            $res = Cookie::has("$name");
            if ($res) {
                $data['status'] = true;
                $data['msg'] = 'ok';
            } else {
                $data['status'] = false;
                $data['msg'] = '网络错误,请稍后重试~';
            }
            echo json_encode($data);
            exit();
        }
  • 相关阅读:
    JS设置Cookie过期时间
    linq to xml
    ToDictionary的用法
    为程序使用内存缓存(MemoryCache)
    NuGet的几个小技巧
    IIS 的几个小技巧
    在Visual Studio中使用NuGet管理项目库
    在ASP.NET MVC中,使用Bundle来打包压缩js和css
    在C#中使用WMI查询进程的用户信息
    WMI测试器
  • 原文地址:https://www.cnblogs.com/zwtqf/p/10071447.html
Copyright © 2011-2022 走看看