Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Cookie不会设置/输出到未来页面_Php_Ajax_Cookies - Fatal编程技术网

Php Cookie不会设置/输出到未来页面

Php Cookie不会设置/输出到未来页面,php,ajax,cookies,Php,Ajax,Cookies,我无法在“images.php”页面上输出cookie。我已经在我的网站的其他区域工作了cookies,但是我不能让它在这里工作。我的表单使用一个ajaxsubmit,它将数据传递到一个PHP文件,然后如果该文件中没有错误,就会将用户重定向到流程的下一步 HTML输入字段 <input type="text" name="price" class="form-control" placeholder="Enter the price you wish to list your item f

我无法在“images.php”页面上输出cookie。我已经在我的网站的其他区域工作了cookies,但是我不能让它在这里工作。我的表单使用一个ajaxsubmit,它将数据传递到一个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>  

$('form.ajax')。在('submit',函数(){
var that=$(此),
url='inc/admin/validate_sell.php',
type=that.attr('method'),
数据={};
that.find('[name]')。每个(函数(索引,值){
var that=$(此),
name=that.attr('name'),
value=that.val();
数据[名称]=值;
});
$.ajax({
url:url,
类型:类型,
数据:数据,
成功:功能(数据){
$(“#response”).html(数据);
}
});
返回false;
});
PHP

setcookie('price',$\u POST['price',time()+3600);
“echo”窗口。位置。替换(“http://localhost/ur/images.php")';  
将来应该在哪个页面回显cookies(images.php)



但是,这不会在“images.php”上返回任何值。

请尝试添加path参数<代码>setcookie('price',$\u POST['price',time()+3600,“/”)如果这是在live Web服务器上而不是在运行localhost时,也可以添加域参数
setcookie('price', $_POST['price'], time()+3600);
echo '<script>window.location.replace("http://localhost/ur/images.php")</script>';  
<?php echo $_COOKIE['price']; ?>