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(); }

浙公网安备 33010602011771号