javascript - PHP Cookie Not Setting via AJAX -
i'm trying set php cookie via ajax. i'm putting 1 variable ("listingid") cookie name. if hard code name (eg. "cmappin220") cookie sets correctly, require variable in name identify it.
ajax:
function myfunc(listingid){ $.ajax({ url: 'cookie.php', type: 'post', data: {listingid:listingid}, datatype: 'html' }).success(function(data){ $('.div66').html(data); }).fail(function(jqxhr, errmsg) { alert("request failed: " + errmsg); }); }
in "cookie.php"
this doesn't work:
<?php $cookiename = 'cmappin' . $_post['listingid']; setcookie($cookiename, '1', time()+30); ?>
this works:
<?php $cookiename = 'cmappin220'; setcookie($cookiename, '1', time()+30); ?>
your problem in post data
data: {listingid:listingid}
you're not quoting name of parameter it's pulling value both name , value. try instead
data: {"listingid":listingid}
Comments
Post a Comment