是否有一个特定的原因,为什么通过AJAX调用传递cookie会对性能或维护代码产生影响或不会产生影响,而不是简单地在PHP内部调用$_COOKIE
?
在这种情况下,我使用此插件在javascript中获取Cookie:Cookie Plugin
通过Ajax调用传递cookie的示例:
$.ajax({
url: 'getCaseManagerReport.php',
method: 'POST',
dataType: 'json',
async: true,
data: {activeDateSelected: Cookies.get('activeDateSelected').replace(/[+]/g, " "), activeProductSelected: Cookies.get('activeProductSelected')}
})
.done(function(response) {
//do stuff
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert("There was a problem during verification. Please contact your System Administrator...");
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
});
});
然后在getCaseManagerReport.php
中$activeDateSelected = $_POST[‘activeDateSelected’];
VS使用$_COOKIE
检索Cookie
$activeDateSelected = $_COOKIE[‘activeDateSelected’];