main.php:
<div id="test" class="test">
<?php include("data.php");?>
</div>
data.php: In this php, i have a few query, and then print some list...Each list in an own DIV tag, and all DIV tag is "closed" when the page is load, except the last one that the user opened. I use cookie to save the the DIV ID to know which i have to open when the page is reload.
JS PART:
var test= $.cookie('test_cook');
$('div[class*="test"]').hide();
var op = $.cookie("test_cook");
alert(op);
$('div.test' + op).show();
$('input:image').click( function() {
var nr = $(this).attr('id').substr(7,2);
$('div.test' + nr).toggle(400);
$.cookie("test", nr, {expires:1 });
});
PHP PART:
In searctest.php a print some list what the user search for, and if they want, can send to database.
include("searchtest.php");
If i reload, or close the page, then cookie is works well, the last opened DIV tag stay open. But after user make a search, and POST it, then the cookie variable will empty.
Could you suggest me something how can i bypass this?
Use Ajax instead of posting. That way the local page context isn't wiped out.
I don't know whats the problem really, but you can force to reload the cookie in the header of the POST reponse.
<?php setcookie(cookieName,$_COOKIE["cookieName"],time, domain,... ); ?>
I think that It's not the better solution..but it can works.
One question. The path of the post request is in the same path? For example, if the cookie is valid in the path /example/ and your post it's going to another path /example2/ the cookie will not works in /example2/ path. In that case, you can to declare the cookie in the root path (/), but I don't know how to do it in that JQuery plug.
Good luck and sorry for my bad english.