I have a page, return.php. It has a line of HTML as follows:
<td><a href="#" dataP="<?= $partNumber[$x] ?>" onclick="popup(this)"><?= substr($avgCost[0],0,6) ?></a></td>
onclick
, this calls the following popup function:
function popup(windowname) {
document.cookie = 'popupPartNumber='+windowname.getAttribute("dataP")+'; expires=Wed, 1 Jan 2070 13:47:11 UTC; path=/'
var x = document.cookie;
console.log(x);
windowname = 'popUpDiv';
blanket_size(windowname);
window_pos(windowname);
toggle('blanket');
toggle(windowname);
}
on this same page, this loads:
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;"">
<a href="#"" onclick="popup(this)"><img src="/img/close.png"></a>
<?php
$popupPartNumber = $_COOKIE['popupPartNumber'];
echo "<pre>";
echo htmlentities($_COOKIE['popupPartNumber'], 3, 'UTF-8');
echo "</pre>";
?>
</div>
When I start this out and I click on the HTML link, I get a console.log output that says:
PHPSESSID=cvbt1gvisul27nccenaeum1hh0; popupPartNumber=123456789
but my php echo output says: null
Why is the cookie that I'm setting correctly in javascript not available to php?
Update
I changed return.php
to say:
$popupPartNumber = $_POST['popupPartNumber']; //part number line
echo "<pre>";
echo "value is: " . $popupPartNumber ;
echo "</pre>";
and I changed the script to read:
var x = windowname.getAttribute("dataP");
$.ajax({
type: 'POST',
url: 'return.php',
data: {popupPartNumber:x},
success:function(data){
alert(data);
}
});
console.log(x); //outputs the correct number.
This isn't working though... I still get no value to the php variable.