Lazaroth
07-06-2008, 01:29 AM
Hi.
I have 2 problems I would like to get answered.
Neither needs any "real" code displayed from my side, since it's not therein the problems lies.
Note that this is also simplified, to better demonstrate what I mean.
1.
I have a page where when a link is pressed ajax is called and it eventually runs a php function.
This function does 2 things. First sets a cookie, then echo's stuff into a predefined layer.
function setUsername($name)
{
setcookie("uname", $name, 0, "/");
echo "Username: " . $_COOKIE["uname"];
}
The problem is that the cookie doesn't exist until ajax is done.
The above code would give an error saying that cookie doesn't not exist.
I've tried sleep etc, but it seems to depend on if ajax has finished.
Why is that so and how can I circumvent this?
2.
Are there any good ways to combine sessions and ajax?
I've tried http://codinginparadise.org/weblog/2005/08/ajax-tutorial-saving-session-across.html but it has flaws.
I can get neither example to work in safari and when the techniques are used in FF/IE,
they only work in a .htm/.html file. If I try them in .php the field/iframe is reset on refresh.
Thanks in advance!
I have 2 problems I would like to get answered.
Neither needs any "real" code displayed from my side, since it's not therein the problems lies.
Note that this is also simplified, to better demonstrate what I mean.
1.
I have a page where when a link is pressed ajax is called and it eventually runs a php function.
This function does 2 things. First sets a cookie, then echo's stuff into a predefined layer.
function setUsername($name)
{
setcookie("uname", $name, 0, "/");
echo "Username: " . $_COOKIE["uname"];
}
The problem is that the cookie doesn't exist until ajax is done.
The above code would give an error saying that cookie doesn't not exist.
I've tried sleep etc, but it seems to depend on if ajax has finished.
Why is that so and how can I circumvent this?
2.
Are there any good ways to combine sessions and ajax?
I've tried http://codinginparadise.org/weblog/2005/08/ajax-tutorial-saving-session-across.html but it has flaws.
I can get neither example to work in safari and when the techniques are used in FF/IE,
they only work in a .htm/.html file. If I try them in .php the field/iframe is reset on refresh.
Thanks in advance!