0

I want to set cookie through AJAX. But I get warning "Cannot modify header" any ideas ?

<?php 

if($_POST['name']){
   setcookie("autosave_blogo_id", "value", time()+10800, '/');
}

?>
$("#button").click(function(){
                    $.ajax({
                    var indata = $('#b_pav').val();
                        type: "POST",
                        url:  "<?php echo "http://" . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>",
                        data: indata,
                        success: function(msg){
            alert(msg);
                        }
                    });
                    return false;
                });
Till Helge
  • 9,253
  • 2
  • 40
  • 56
andys
  • 708
  • 3
  • 11
  • 29

1 Answers1

-1

You need to set your cookie before anything else is being output from your script.

Borniet
  • 3,544
  • 4
  • 24
  • 33