我无法在页面'images.php'上输出cookie。我已经在我的网站的其他区域工作了cookie,但我不能让它在这里工作。我的表单使用AJAX提交,将数据传递给PHP文件,然后如果该文件中没有错误,则将用户重定向到该过程的下一步。
HTML输入字段
<input type="text" name="price" class="form-control" placeholder="Enter the price you wish to list your item for" />
AJAX提交
<script type="text/javascript">
$('form.ajax').on('submit', function () {
var that= $(this),
url = 'inc/admin/validate_sell.php',
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(data) {
$("#responce").html(data);
}
});
return false;
});
</script>
PHP
setcookie('price', $_POST['price'], time()+3600);
echo '<script>window.location.replace("http://localhost/ur/images.php")</script>';
将在(images.php)上回显cookie的未来页面。
<?php echo $_COOKIE['price']; ?>
然而,这在'images.php'上没有返回任何值。