MouseOver时启动PHP-Session
问题描述:
$("#profile_bar").mouseover(function(){
<?php $_SESSION['sessionasdf'] = 'asdf'; ?>
});
Hello! I have been busy with this for an hour, but I'm deadbrain now. Can someone help me out or give me a hint? Is the function I wrote above, even possible?
Thanks in advance!
$(“#profile_bar”)。mouseover(function(){
&lt;? php $ _SESSION ['sessionasdf'] ='asdf';?&gt;
});
code> pre>
您好! 我已经忙了一个小时了,但我现在已经死了。 有人可以帮助我或给我一个暗示吗? 我上面写的函数是否可能? p>
提前致谢! p>
div>
答
You need an Ajax Request to do this. You can't simply start a session in a script that's already been loaded.
$("#profile_bar").mouseover(function() {
$.ajax({
url: "sessionStartPage.php",
cache: false,
success: function(data) {
alert("session has begun. Refreshing page now");
location.reload(); //reload the page to load session variables
}
});
});
答
As I said you have to use a technique called AJAX.. So its time to start learning:) http://www.smashingmagazine.com/2008/10/16/50-excellent-ajax-tutorials/
答
PHP run on server, JQuery(the javascript) run on browser.That's different. And you can start the session at every page on server, rather than by the event on browser.