zoukankan      html  css  js  c++  java
  • ajax获取网页cookie值,并处理页面信息

    注:非必要情况。可直接在后台操作数据,不适用ajax更简单

     ($sn_arr = $_COOKIE;)   ---------------获取所有cookie进行筛选操作 

    1.js(页面加载0.5ms后执行函数)

     $(function(){
            setTimeout(function () {
                $.ajax({
                    url:"/supplierbuyer/order/getCookie",
                    data:{
                    },
                    type:"POST",
                    dataType:"JSON",
                    success:function(data){
                        if(data.status==true){
                            //处理cookie的数据
                            var cookie_content = data['sn_arr'];
                            $.each(cookie_content, function(index, item){
                                if (index.startsWith("order_sn_")) {
                                    var order_sn = index.substr(9);
                                    $('.'+order_sn).text('');
                                    $('.'+order_sn).parent().prev().css("background","");
                                }
                            });
                        }else{
                            console.log(data);
                            return false;
                        }
                    }
                });
            }, 0.5);
    
        });

    2.php

     /**
         * 获取cookie
         */
        public function getCookie()
        {
            $sn_arr = $_COOKIE;
            if ($sn_arr) {
                $data['status'] = true;
                $data['sn_arr'] = $sn_arr;
                $data['msg'] = 'ok';
            } else {
                $data['status'] = false;
                $data['sn_arr'] = '';
                $data['msg'] = '网络错误,请稍后重试~';
            }
            echo json_encode($data);
            exit();
        }
  • 相关阅读:
    Django部署到服务器
    springboot使用Redis缓存
    ubuntu下pip更换国内源
    ubuntu环境变量文件
    python open找不到路径
    centos 8 安装nginx
    centos8 mysql8的远程访问
    centos 8 安装mysql-server 8
    今日收获
    今日收获
  • 原文地址:https://www.cnblogs.com/zwtqf/p/10071585.html
Copyright © 2011-2022 走看看