注:非必要情况。可直接在后台操作数据,不适用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(); }