I've dug deep for this one and can't seem to locate the answer, most answers will show you how to set and retrieve cookies within a language, but not cross language.
I need to pass a php array into a cookie and then retrieve the contents on another page with jquery so that I can dynamically set the options on a dropdown menu. (For a bootstrap dropdown menu, not a standard select dropdown) I have echoed out the php array to confirm it is present and it is.
I am using the jquery cookie plugin.
PHP snippet:
while ($row = mysql_fetch_assoc($result)) {
//Get Dropdown options
$wnDropdown[] = '<li value=' . $row['id'] . '>' . $row['name'] . '</li>';
} //end while
mysql_close();
} //end inner if
} //end else
//Cookie needed
setcookie("wnDropdown", json_encode($wnDropdown));
jQuery:
$(document).ready(function() {
var result = JSON.parse($.cookie('wnDropdown'));
alert(result);
});
The result alerted returns 'null'.
What am I missing?
If more information is needed, let me know.