ajax抓取网页内容( ():)
优采云 发布时间: 2021-09-08 22:07ajax抓取网页内容(
():)
ajax获取网页的cookie值并处理页面信息
注意:没有必要。后台可以直接操作数据,不用ajax更简单
($sn_arr = $_COOKIE;) ---------------获取所有cookies进行过滤操作
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();
}
posted @ 2018-12-05 16:13 很有趣。阅读(4510)review(0)edit
)